locating an alloc error
| Sat, 2008-03-15 02:19 | |
|
i wrote the most basic hello world GUI program which also implements an active object which appears after a fixed time interval when instantiated. The active object class's name is CDelayedHello its object is iDelayedHello. .Here is what my CDelayedHello looks like: #include "SimpleEx.h"Now as soon as i exit the application an alloc error ocurrs The error dissappears if i comment out the instantiation of iDelayedHello in APPView's ConstructL. My destructor of the active object class looks fine to me... so wher's the memory leak happening??? plz help |
|






Forum posts: 56
make sure that you are deleting iDelayedHello in ~CSimpleExAppView
void CSimpleExAppView:: ~CSimpleExAppView()
{
if(iDelayedHello)
delete iDelayedHello;
}
Forum posts: 1058
if(iDelayedHello)delete iDelayedHello;
Just a small comment: Checking the iDelayedHello pointer before delete is unnecessary. C++ delete includes that NULL check itself already and silently does just nothing if the pointer is NULL.
Otherwise, I would agree: That's the probable source of the memory leak, given the information in the post.
René Brunner
Forum posts: 56
agree
Forum posts: 18
Thanks.. no errors now.but as rbrunner said.. doesnt it automatically happen in the destructor? why the need to write somethin that actuaaly happens (which din't happen in this case
)
Forum posts: 1058
Ah, we seem to have a little misunderstanding here: Nothing happens automatically in the destructor. I just said that in C++ instead of writing
if (pointer) delete pointer;you can just write
delete pointer;without checking anything, because delete does that already for you.
René Brunner
Forum posts: 18
Just wen i thought that my application was leak proof... got the familiar shock again!!! Thanks rbrunner for the info... i'm hopin u'l come to my rescue again
The aim of the followin file is actually to read an incoming SMS and programmatically delete it. At LINE X in the following snippet i shall be replacing the code for displaying content l8r. Right now its just a message box.
The troublemaker this time is my SMSReceiver class. similar alloc error on exit. Here's the code for the class
CSMSReceiver::CSMSReceiver()
{
// No implementation required
}
CSMSReceiver::~CSMSReceiver()
{
if(iSession)
delete iSession;
//iSession = NULL;
}
CSMSReceiver* CSMSReceiver::NewL()
{
CSMSReceiver* self = new(ELeave)CSMSReceiver();
self->ConstructL();
return self;
}
void CSMSReceiver::ConstructL()
{
iSession = CMsvSession::OpenSyncL(*this);
}
void CSMSReceiver::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
{
static TInt iNewMessageId = 0;
switch (aEvent)
{
// A new entry has been created in the message server
case EMsvEntriesCreated:
{
if(*(static_cast<TMsvId *>(aArg2)) == KMsvGlobalInBoxIndexEntryId)
{
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection *>(aArg1);
iNewMessageId = entries->At(0);
}
break;
}
case EMsvEntriesChanged:
{
TMsvId* entryId = static_cast<TMsvId*>(aArg2); // entry id from the session event
if (*entryId == KMsvGlobalInBoxIndexEntryId) // new entry has been created in Inbox folder
{
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
TInt index = entries->Find(iNewMessageId);
if(KErrNotFound == index)
{
break;
}
_LIT(KMessage,"Message!!!!");
CEikonEnv::Static()->AlertWin(KMessage); //LINE X
entries=NULL;
TMsvId entryId2;
CMsvEntry* entry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
entries=entry->ChildrenL();
entry=NULL;
entryId2=entries->At(0);
entry=iSession->GetEntryL(entryId2);
CleanupStack::PushL(entry);
TMsvEntry msvEntry = entry->Entry();
//entry->DeleteL(msvEntry.Id());
CleanupStack::PopAndDestroy(entry); // entry
_LIT(KMsg,"Message deleted");
CEikonEnv::Static()->AlertWin(KMsg); //LINE Y
}
break;
}
// Handle close session
case EMsvCloseSession:
{
iSession->CloseMessageServer();
break;
}
// Handle server terminated
case EMsvServerTerminated:
{
iSession->CloseMessageServer();
break;
}
default:
{
break;
}
}
I'm even deleting the object in my view class's destructor this time.
..
.
CSimpleExAppView::~CSimpleExAppView()
{
if(iDelayedHello)
delete iDelayedHello;
if(rcvr)
delete rcvr;
}
.
..
Another wird thing happned when i ran this. On the arrival of a new message, the LINE X dialog popped only once, while the LINE Y dialog popped up twice !!!
Forum posts: 56
here is the leak..
CMsvEntry* entry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
CleanupStack::PushL(entry);
entries=entry->ChildrenL();
CleanupStack::PopAndDestroy(entry); // entry
entry=NULL;
entryId2=entries->At(0);
entry=iSession->GetEntryL(entryId2);
CleanupStack::PushL(entry);
TMsvEntry msvEntry = entry->Entry();
//entry->DeleteL(msvEntry.Id());
CleanupStack::PopAndDestroy(entry); // entry
delete entries;
i think bold lines should solve the problem...
Forum posts: 18
It seems symbian never fails to surprise you!! The leak is still there and is solely because of the alertwin function.. Here's my new HandleSessionEventL function which still is the cause of the leak:
case EMsvEntriesCreated:
{
break;
}
case EMsvEntriesChanged:
{
CEikonEnv::Static()->AlertWin(_L("Message!!"));
break;
}
Commenting out the alert shows no leak.
Regarding the double message box problem i asked above, i checked out during debug, for every new message, the EMsvEntriesChanged event gets called twice (No clue why) I need to delete the incoming message but due to the event being called twice, another existing message in the inbox is geting deleted!! Still holed up by these two issues (memory leak & double deletion) help needed urgently!!
Forum posts: 56
i think you need HookLogger now..
http://www.newlc.com/Hooklogger-Tracking-leaked-heap.html