Click here to Skip to main content
15,919,423 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionheap corruption Pin
devvvy23-Aug-07 1:12
devvvy23-Aug-07 1:12 
AnswerRe: heap corruption Pin
jhwurmbach23-Aug-07 1:22
jhwurmbach23-Aug-07 1:22 
Generaldifferent dll - must use SysAllocString and SysFreeString? Pin
devvvy23-Aug-07 14:01
devvvy23-Aug-07 14:01 
GeneralRe: different dll - must use SysAllocString and SysFreeString? Pin
jhwurmbach23-Aug-07 21:37
jhwurmbach23-Aug-07 21:37 
AnswerRe: heap corruption Pin
Iain Clarke, Warrior Programmer23-Aug-07 1:33
Iain Clarke, Warrior Programmer23-Aug-07 1:33 
GeneralRe: heap corruption Pin
Russell'23-Aug-07 1:49
Russell'23-Aug-07 1:49 
GeneralRe: heap corruption Pin
devvvy23-Aug-07 13:51
devvvy23-Aug-07 13:51 
GeneralRe: heap corruption Pin
Iain Clarke, Warrior Programmer23-Aug-07 21:54
Iain Clarke, Warrior Programmer23-Aug-07 21:54 
Yes, if you do
XXXX *pX = new XXXX [n];
then you should get rid of it with
delete [] pX

Try the above code with:
class XXXX
{
public:
    XXXX ()
    {
        TRACE0("XXXX Constructed\n");
    }
    ~XXXX ()
    {
        TRACE0("XXXX Destructed\n");
    }
};

main ()
{
    XXXX *pX = new XXXX [4];
    delete pX;
     XXXX *pX = new XXXX [4];
    delete [] pX;
}


In answer to your main question...

It appears that you have memory allocated from within the DLL, and freed from within the EXE. This is another example of using different memory buckets, and can lead to difficulties. While I haven't been bitten by this myself, either I'm lucky, or careful. I didn't think new / delete suffered from this problem like malloc & free, but I could be wrong.

There are a number of ways to deal with this... For an object, you could use a Release () method, and get it to delete itself - and the code for that would be in the same dll as the creation.
For chunks of memory, windows has a bunch of LocalAllocs, GlobalAllocs, which point to the same functions under Win32 I think.
Or look at the IMalloc interface for allocating / freeing memory.

Good luck,

Iain.



GeneralRe: heap corruption Pin
devvvy29-Aug-07 2:58
devvvy29-Aug-07 2:58 
AnswerRe: heap corruption Pin
ghle27-Aug-07 4:24
ghle27-Aug-07 4:24 
GeneralRe: heap corruption Pin
devvvy29-Aug-07 2:57
devvvy29-Aug-07 2:57 
QuestionSmall question Pin
Chen-XuNuo22-Aug-07 23:01
Chen-XuNuo22-Aug-07 23:01 
AnswerRe: Small question Pin
fefe.wyx22-Aug-07 23:12
fefe.wyx22-Aug-07 23:12 
AnswerRe: Small question Pin
toxcct22-Aug-07 23:17
toxcct22-Aug-07 23:17 
AnswerRe: Small question Pin
Roger Broomfield22-Aug-07 23:20
Roger Broomfield22-Aug-07 23:20 
JokeRe: Small question Pin
Cedric Moonen22-Aug-07 23:22
Cedric Moonen22-Aug-07 23:22 
GeneralRe: Small question Pin
toxcct22-Aug-07 23:25
toxcct22-Aug-07 23:25 
GeneralRe: Small question Pin
Roger Broomfield22-Aug-07 23:32
Roger Broomfield22-Aug-07 23:32 
GeneralRe: Small question Pin
Naveen22-Aug-07 23:33
Naveen22-Aug-07 23:33 
GeneralRe: Small question Pin
Naveen22-Aug-07 23:30
Naveen22-Aug-07 23:30 
Questionregistry cleaner for window xp Pin
niki dutta22-Aug-07 22:57
niki dutta22-Aug-07 22:57 
AnswerRe: registry cleaner for window xp Pin
toxcct22-Aug-07 22:58
toxcct22-Aug-07 22:58 
AnswerRe: registry cleaner for window xp Pin
Russell'22-Aug-07 23:05
Russell'22-Aug-07 23:05 
AnswerRe: registry cleaner for window xp Pin
Rajesh R Subramanian23-Aug-07 0:21
professionalRajesh R Subramanian23-Aug-07 0:21 
GeneralRe: registry cleaner for window xp Pin
toxcct23-Aug-07 0:26
toxcct23-Aug-07 0:26 

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.