Click here to Skip to main content
15,888,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: initialization of member variables Pin
khan++27-Feb-06 19:21
khan++27-Feb-06 19:21 
AnswerRe: initialization of member variables Pin
Vinaya27-Feb-06 19:24
Vinaya27-Feb-06 19:24 
GeneralRe: initialization of member variables Pin
Kranti125198427-Feb-06 19:32
Kranti125198427-Feb-06 19:32 
GeneralRe: initialization of member variables Pin
Vinaya27-Feb-06 19:40
Vinaya27-Feb-06 19:40 
GeneralRe: initialization of member variables Pin
sunit527-Feb-06 19:53
sunit527-Feb-06 19:53 
GeneralRe: initialization of member variables Pin
Salad Bar27-Feb-06 19:43
Salad Bar27-Feb-06 19:43 
GeneralRe: initialization of member variables Pin
Kranti125198427-Feb-06 19:46
Kranti125198427-Feb-06 19:46 
QuestionThe Destructor can't cleanup the memory? Pin
signbit27-Feb-06 18:17
signbit27-Feb-06 18:17 
Hello,

I have an unmanaged document class in my code, that looks like this

class MyDocument
{
public: 
    MyDocument()
  {
     // Initilize the dynamic structures throught call to 'new' operator
  }
    ~MyDocument()
  {
     // Cleanup the code
     this->CleanUp();   // When the function is called, it can't access the memory
  }
     bool CleanUp()
  {
     // Clean all the memory using 'delete' operator
  }
};

Then I have a pointer to it in my Form (that is a .NET managed class, a Form object).

MyDocument *document;

Inside the Constructor of the form, I initialize the document with

this->document = new MyDocument();

The Dispose() function of the Form has the code:

if(disposing && document)
        delete document;


During the lifetime of the program, several time i need to free the resouces of the document class and allocated new ones, like this:

document->CleanUp(); // Code runs alright
// allocated new resources to the document


However when I close the application (i.e. the destructor of the form runs), I get an error that CleanUp() can't access the memory (because it is not accessible, may be it has been cleaned already).

Could any one please explain why I can call CleanUp() anywhere in my program and I get no error (the memory gets cleaned as expected), and I get a 'Memory Not Accessible' error when I call it from the destrcutor. (I tried to comment out the code in the destructor, and the application gets cured i.e. It produces no errors/exceptions etc.


- A programmer's national anthem; "AAAAAHHHHH!!!!"
AnswerRe: The Destructor can't cleanup the memory? Pin
Nibu babu thomas27-Feb-06 18:33
Nibu babu thomas27-Feb-06 18:33 
GeneralRe: The Destructor can't cleanup the memory? Pin
signbit27-Feb-06 18:36
signbit27-Feb-06 18:36 
GeneralRe: The Destructor can't cleanup the memory? Pin
Nibu babu thomas27-Feb-06 18:47
Nibu babu thomas27-Feb-06 18:47 
GeneralRe: The Destructor can't cleanup the memory? Pin
signbit27-Feb-06 18:51
signbit27-Feb-06 18:51 
GeneralRe: The Destructor can't cleanup the memory? Pin
Nick_Kisialiou27-Feb-06 19:27
Nick_Kisialiou27-Feb-06 19:27 
GeneralRe: The Destructor can't cleanup the memory? Pin
Johann Gerell27-Feb-06 20:28
Johann Gerell27-Feb-06 20:28 
GeneralRe: The Destructor can't cleanup the memory? Pin
Stephen Hewitt27-Feb-06 21:30
Stephen Hewitt27-Feb-06 21:30 
GeneralRe: The Destructor can't cleanup the memory? Pin
signbit27-Feb-06 22:09
signbit27-Feb-06 22:09 
GeneralRe: The Destructor can't cleanup the memory? Pin
Stephen Hewitt27-Feb-06 23:23
Stephen Hewitt27-Feb-06 23:23 
QuestionThe Image is being displayed upside down :( Pin
signbit27-Feb-06 18:02
signbit27-Feb-06 18:02 
AnswerRe: The Image is being displayed upside down :( Pin
Christian Graus27-Feb-06 18:14
protectorChristian Graus27-Feb-06 18:14 
GeneralRe: The Image is being displayed upside down :( Pin
signbit27-Feb-06 18:19
signbit27-Feb-06 18:19 
GeneralRe: The Image is being displayed upside down :( Pin
Christian Graus27-Feb-06 18:21
protectorChristian Graus27-Feb-06 18:21 
GeneralRe: The Image is being displayed upside down :( Pin
signbit27-Feb-06 18:32
signbit27-Feb-06 18:32 
GeneralRe: The Image is being displayed upside down :( Pin
Christian Graus27-Feb-06 18:44
protectorChristian Graus27-Feb-06 18:44 
GeneralRe: The Image is being displayed upside down :( Pin
signbit27-Feb-06 18:55
signbit27-Feb-06 18:55 
GeneralRe: The Image is being displayed upside down :( Pin
signbit27-Feb-06 18:25
signbit27-Feb-06 18:25 

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.