Click here to Skip to main content
15,796,456 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to get the value of a check box in a dialog box Pin
Maxwell Chen19-Sep-07 21:32
Maxwell Chen19-Sep-07 21:32 
AnswerRe: how to get the value of a check box in a dialog box Pin
David Crow20-Sep-07 3:54
David Crow20-Sep-07 3:54 
QuestionMemory Leak problem Pin
GauranG Shah19-Sep-07 21:07
GauranG Shah19-Sep-07 21:07 
GeneralRe: Memory Leak problem Pin
Maxwell Chen19-Sep-07 21:30
Maxwell Chen19-Sep-07 21:30 
AnswerRe: Memory Leak problem Pin
ThatsAlok19-Sep-07 21:33
ThatsAlok19-Sep-07 21:33 
GeneralRe: Memory Leak problem Pin
Cedric Moonen19-Sep-07 21:43
Cedric Moonen19-Sep-07 21:43 
AnswerRe: Memory Leak problem Pin
Cedric Moonen19-Sep-07 21:42
Cedric Moonen19-Sep-07 21:42 
AnswerRe: Memory Leak problem Pin
Emilio Garavaglia19-Sep-07 21:42
Emilio Garavaglia19-Sep-07 21:42 
The memory leak control implemented on the CRT overloads the new and delete operators to add some extra memory to contain some signatures that are tracked by a global data structure.
At end, is something is wrong between this structure and the related allocated memory a warning is reported.

In your case your obj pointer is also a global data. But since the initialization order of global data is not predictable (in the sense that it depends on the order the linker links the modules) probably your "new" call happens before the tracking structure is properly initialized (hence, it isn't tracked).
But the delete is. Hence the misleading and the resulting report.

Try this:
class myhandle
{
    myclass* p;
public:
    myhandle() :p(new myclass) {}
    ~myhandle() { delete p; }
    myclass* operator->() const { return p; }
};

myhandle thehandle;

INT WINAPI WinMain( ....)
{
   myhandle->do_something_with_myclass(...)
   return 0;
}


Now allocation and deallocation are wrapped in ctor / dtor.
When thehandle is created the compiler will place an "atexit" to invoke the destructor.
Since the order of destruction is the inverse of the order of construction, you're so granted that either both new and delete are tracked or none of them is. Both case are coherent.

<edit>
I see just now ThatsAlok writing "use auto_ptr".
In fact std::auto_ptr behave just like myhandle in respect to construction / destruction.
</edit>


2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:

AnswerRe: Memory Leak problem Pin
nbugalia19-Sep-07 21:57
nbugalia19-Sep-07 21:57 
AnswerOff Topic Pin
toxcct19-Sep-07 23:08
toxcct19-Sep-07 23:08 
GeneralRe: Off Topic Pin
GauranG Shah20-Sep-07 0:11
GauranG Shah20-Sep-07 0:11 
GeneralRe: Off Topic Pin
toxcct20-Sep-07 0:24
toxcct20-Sep-07 0:24 
GeneralRe: Off Topic Pin
GauranG Shah20-Sep-07 2:57
GauranG Shah20-Sep-07 2:57 
GeneralRe: Off Topic Pin
toxcct20-Sep-07 2:58
toxcct20-Sep-07 2:58 
GeneralRe: Off Topic Pin
David Crow20-Sep-07 3:51
David Crow20-Sep-07 3:51 
GeneralRe: Off Topic Pin
toxcct20-Sep-07 3:54
toxcct20-Sep-07 3:54 
QuestionPlease help regarding the following error Pin
hits0719-Sep-07 19:57
hits0719-Sep-07 19:57 
AnswerRe: Please help regarding the following error Pin
nbugalia19-Sep-07 20:27
nbugalia19-Sep-07 20:27 
GeneralRe: Please help regarding the following error Pin
hits0719-Sep-07 20:41
hits0719-Sep-07 20:41 
GeneralRe: Please help regarding the following error Pin
nbugalia19-Sep-07 21:06
nbugalia19-Sep-07 21:06 
GeneralRe: Please help regarding the following error Pin
David Crow20-Sep-07 3:49
David Crow20-Sep-07 3:49 
Questionadd files and foldder selection box on button click Pin
Dhiraj kumar Saini19-Sep-07 19:44
Dhiraj kumar Saini19-Sep-07 19:44 
AnswerRe: add files and foldder selection box on button click Pin
nbugalia19-Sep-07 20:23
nbugalia19-Sep-07 20:23 
QuestionHow to avoid flickering in CListCtrl Pin
shir_k19-Sep-07 19:11
shir_k19-Sep-07 19:11 
AnswerRe: How to avoid flickering in CListCtrl Pin
Nelek19-Sep-07 21:08
protectorNelek19-Sep-07 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.