Click here to Skip to main content
15,071,899 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 20:32
MemberMaxwell Chen19-Sep-07 20:32 
AnswerRe: how to get the value of a check box in a dialog box Pin
David Crow20-Sep-07 2:54
MemberDavid Crow20-Sep-07 2:54 
QuestionMemory Leak problem Pin
GauranG Shah19-Sep-07 20:07
MemberGauranG Shah19-Sep-07 20:07 
GeneralRe: Memory Leak problem Pin
Maxwell Chen19-Sep-07 20:30
MemberMaxwell Chen19-Sep-07 20:30 
AnswerRe: Memory Leak problem Pin
ThatsAlok19-Sep-07 20:33
MemberThatsAlok19-Sep-07 20:33 
GeneralRe: Memory Leak problem Pin
Cedric Moonen19-Sep-07 20:43
MemberCedric Moonen19-Sep-07 20:43 
AnswerRe: Memory Leak problem Pin
Cedric Moonen19-Sep-07 20:42
MemberCedric Moonen19-Sep-07 20:42 
AnswerRe: Memory Leak problem Pin
Emilio Garavaglia19-Sep-07 20:42
MemberEmilio Garavaglia19-Sep-07 20: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 20:57
Membernbugalia19-Sep-07 20:57 
AnswerOff Topic Pin
toxcct19-Sep-07 22:08
Membertoxcct19-Sep-07 22:08 
GeneralRe: Off Topic Pin
GauranG Shah19-Sep-07 23:11
MemberGauranG Shah19-Sep-07 23:11 
GeneralRe: Off Topic Pin
toxcct19-Sep-07 23:24
Membertoxcct19-Sep-07 23:24 
GeneralRe: Off Topic Pin
GauranG Shah20-Sep-07 1:57
MemberGauranG Shah20-Sep-07 1:57 
GeneralRe: Off Topic Pin
toxcct20-Sep-07 1:58
Membertoxcct20-Sep-07 1:58 
GeneralRe: Off Topic Pin
David Crow20-Sep-07 2:51
MemberDavid Crow20-Sep-07 2:51 
GeneralRe: Off Topic Pin
toxcct20-Sep-07 2:54
Membertoxcct20-Sep-07 2:54 
QuestionPlease help regarding the following error Pin
hits0719-Sep-07 18:57
Memberhits0719-Sep-07 18:57 
AnswerRe: Please help regarding the following error Pin
nbugalia19-Sep-07 19:27
Membernbugalia19-Sep-07 19:27 
GeneralRe: Please help regarding the following error Pin
hits0719-Sep-07 19:41
Memberhits0719-Sep-07 19:41 
GeneralRe: Please help regarding the following error Pin
nbugalia19-Sep-07 20:06
Membernbugalia19-Sep-07 20:06 
GeneralRe: Please help regarding the following error Pin
David Crow20-Sep-07 2:49
MemberDavid Crow20-Sep-07 2:49 
Questionadd files and foldder selection box on button click Pin
Dhiraj kumar Saini19-Sep-07 18:44
MemberDhiraj kumar Saini19-Sep-07 18:44 
AnswerRe: add files and foldder selection box on button click Pin
nbugalia19-Sep-07 19:23
Membernbugalia19-Sep-07 19:23 
QuestionHow to avoid flickering in CListCtrl Pin
shir_k19-Sep-07 18:11
Membershir_k19-Sep-07 18:11 
AnswerRe: How to avoid flickering in CListCtrl Pin
Nelek19-Sep-07 20:08
protectorNelek19-Sep-07 20: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.