Memory leak
| Fri, 2008-01-11 10:00 | |
|
Hi Thank you very much
//############# VIEW ##############
void CMyAppView::DoActivateL(const TVwsViewId& ,TUid ,const TDesC8& )
{
if ( !iContainer )
{
iContainer = CMyAppViewContainer::NewL(this);
iContainer->SetMopParent(this);
TRect rect = ClientRect();
iContainer->ConstructL(rect);
AppUi()->AddToStackL( *this, iContainer );
SetTitlePaneL();
iContainer->MakeVisible( ETrue );
}
}
void CMyAppView::DoDeactivate()
{
if (iContainer)
{
AppUi()->RemoveFromStack(iContainer);
delete iContainer;
}
}
//############# VIEW CONTAINER ##############
void CMyAppViewContainer::ConstructL( const TRect& aRect )
{
CreateWindowL();
SetRect( aRect );
MakeListBoxL();
ActivateL();
DrawNow();
}
CMyAppViewContainer::~CMyAppViewContainer()
{
if(iFindBox)
delete iFindBox;
if(iListBox)
delete iListBox;
if (textArray)
delete textArray; //### E32User Cbase 21 error message!
}
void CMyAppViewContainer::MakeListBoxL()
{
iListBox = new( ELeave ) CAknSingleStyleListBox();
iListBox->ConstructL(this,EAknListBoxSelectionList);
//### textArray:tried also as a local var
textArray = new (ELeave) CDesCArrayFlat(iArrayCount);
//### here I put values to textArray using AppendL()
iListBox->Model()->SetItemTextArray(textArray);
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
iListBox->SetRect(Rect());
iFindBox = CreateFindBoxL(iListBox, iListBox->Model(),CAknSearchField::ESearch);
SizeChanged();
iListBox->ActivateL();
iListBox->SetCurrentItemIndex(0);
UpdateScrollBar(iListBox);
}
|
|






Forum posts: 1242
With this statement
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);you hand the array over to the listbox that will own it and also free it. If you try to free the array yourself (a second time, then), this won't work.
I am not quite sure, but I think the problem is here:
void CMyAppView::DoDeactivate(){
if (iContainer)
{
AppUi()->RemoveFromStack(iContainer);
delete iContainer;
}
}
'delete iContainer' contrary to what you probably expect does *not* set 'iContainer' to NULL. Try to set it to NULL after the delete and check what happens.
René Brunner
Forum posts: 145
Thank you very much rbrunner
I made these 2 changes (set container to null and not deleting the textArray).
I still get the "memory full" error,
this happens after many switches from a setting list to this view.
I also got one time (during some changes and tests) a strange error: "aknlayouttreepan 6".
Do you have any idea what this error means (searches resulted with nothing)?
Can it be related to the memory problem?
Can you please refer me to a good article about releasing memory in symbian ? (I found a few but they didn't give me enough info)
Thank you