Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Tracking new/delete in C++

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
cstangle Posted - Oct 16 2008 : 9:33:01 PM
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
4   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Oct 18 2008 : 1:32:31 PM
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.
GennadiyKorol Posted - Oct 17 2008 : 7:44:34 PM
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.
gmit Posted - Oct 17 2008 : 5:09:57 PM
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)?
feline Posted - Oct 17 2008 : 09:21:52 AM
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/

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000