Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Tracking new/delete in C++
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cstangle
Starting Member

1 Posts

Posted - Oct 16 2008 :  9:33:01 PM  Show Profile  Reply with Quote
I propose adding the ability to search through a solution to find all locations where objects of a specific type are being newed or deleted in C++. I imagine the information necessary to do this is already parsed into the VA database. Speaking from many wasted hours on my last project, it would be incredibly useful for tracking down memory leaks. Please respond at your earliest convenience whether it would be possible to add this in an upcoming release.

Best,
Charlie

feline
Whole Tomato Software

United Kingdom
18942 Posts

Posted - Oct 17 2008 :  09:21:52 AM  Show Profile  Reply with Quote
You are talking about static code analysis here, which is not something that VA tries to do. We do not have any current plans to try and add this sort of feature.

One simple reason why is consider the code:

#ifdef CONDITION_ONE
new MyClass();
#else
new MyClass(0, 1, 2);
#endif

How many new statements are there? VA see's two of them, since it is designed to parse and be active inside inactive code, to help you write it.

Lint is a well known static analysis tool: http://www.gimpel.com/

zen is the art of being at one with the two'ness
Go to Top of Page

gmit
Whole Tomato Software

Croatia
90 Posts

Posted - Oct 17 2008 :  5:09:57 PM  Show Profile  Reply with Quote
feline, it's the same type of 'static analysis' as 'find reference' functionality already is. It would be very useful addition.


cstangle, I haven't verified, but, I think that new operators will be found if you issue 'find reference' on class name. However, why don't you use some of runtime new/delete overload helpers which track your memory usage (if you don't have access to BoundsChecker or Purify)?
Go to Top of Page

GennadiyKorol
Ketchup Master

Israel
54 Posts

Posted - Oct 17 2008 :  7:44:34 PM  Show Profile  Reply with Quote
I might be jumping the gun here, but why using delete in C++?

Standard containers and boost::shared_ptr eliminate the need in the delete in 99% of the cases and are considered a much better coding style.

I cannot imagine programming C++ without smart pointers that remove all the head ache of manual memory management.

Correctness might be a theoretical concept but incorrectness has practical implications.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18942 Posts

Posted - Oct 18 2008 :  1:32:31 PM  Show Profile  Reply with Quote
gmit it really depends on what you mean, and what people are asking for here. Consider this example function:

void countMemoryUsedAndFreed(bool bParam)
{
    CMyClass pData = NULL;
    if(true == bParam)
    {
        pData = new CMyClass(true, 1, 1)
    }
    else
    {
        pData = new CMyClass()
    }

    // ...

    delete pData;
}


I have been kind by calling delete explicitly. There is going to be a lot of code that does this even if there are alternate methods.

Now consider Find References, the correct count for "new" is 2. For the original request what is the correct count? I don't know, since it depends on the exact expectations for this tool.

I can make a case that new and delete can only be tracked at run time, due to conditional code and user interaction. Just looking at static analysis counting memory creation and deletion, when you consider copy constructors, over loaded operators, etc, is something that is well beyond VA's current scope. It raises problems we don't current even try to solve.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000