//the container class creates an Engine CFileListEngine
void CPicContainer1::ConstructL(const TRect& aRect)
{
CreateWindowL();
iListBox = new (ELeave) CAknDoubleLargeStyleListBox;
iListBox->SetContainerWindowL( *this );
iListBox->ConstructL( this, EAknListBoxMarkableList);
iListBox->SetMopParent(this);
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iAppEngine = new (ELeave) CFileListEngine;
SetFileList();
iListBox->ActivateL();
SetRect(aRect);
ActivateL();
}
void CPicContainer1::SetFileList()
{
TInt entries;
entries = iAppEngine->StartFileList();
CDesCArray* items = new (ELeave) CDesCArrayFlat( entries );
CArrayPtr<CGulIcon>* iIconList = new ( ELeave ) CAknIconArray( entries );
CleanupStack::PushL( iIconList );
iAppEngine->GetFileListItems(items, iIconList);
iListBox->Model()->SetItemTextArray(items);
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
iListBox->ItemDrawer()->ColumnData()->SetIconArray( iIconList );
CleanupStack::PopAndDestroy();
iListBox->HandleItemAdditionL();
iListBox->SetCurrentItemIndex(0);
iAppEngine->EndFileList();//closing the file server session
}
//the engine class CFileListEngine
_LIT(KFileTimeFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3");
_LIT(KImageDescription, "%d\t%s\t%s");
TInt CFileListEngine::StartFileList()
{
if (iDirList)
{
delete iDirList;
iDirList = 0;
}
path = TPAlbSettings::RootImageFolderLC();
User::LeaveIfError(iFsSession.Connect());
error = iFsSession.GetDir(path->Des(), KEntryAttNormal,ESortByName,iDirList);
iFileCount=iDirList->Count();
return iFileCount;
}
void CFileListEngine::GetFileListItems(CDesCArray* aItems, CArrayPtr<CGulIcon>* aIconList)
{
if(!iDirList)
return;
CPAlbImageData* image_data = CPAlbImageData::NewL();
CleanupStack::PushL( image_data );
CPAlbImageUtil* image_util = CPAlbImageUtil::NewL();
CleanupStack::PushL( image_util );
for (TInt i=0;i<iDirList->Count();i++)
{
CFbsBitmap* thumbnail = NULL;
HBufC* file_name = HBufC::NewLC( path->Length() + (*iDirList)[i].iName.Length() );
file_name->Des().Copy( path->Des() );
file_name->Des().Append( (*iDirList)[i].iName );
TParse parser;
parser.Set( file_name->Des(), NULL, NULL );
if ( ( parser.Ext().Compare( _L(".jpg") ) == 0 ) || ( parser.Ext().Compare( _L(".gif") ) == 0 ) )
{
image_data->SetImageNameL( ( *iDirList )[i].iName );
image_data->SetSubFolderL( path->Des() );
thumbnail = image_util->GetThumbnailL( *image_data );
CleanupStack::PushL(thumbnail);
CGulIcon* icon = CGulIcon::NewL( thumbnail );
CleanupStack::Pop( thumbnail );
CleanupStack::PushL( icon );
aIconList->AppendL( icon );
CleanupStack::Pop( icon );
TTime time;
TBuf<64> s_time;
iFsSession.Modified( file_name->Des(), time );
time.FormatL( s_time, KFileTimeFormat );
TBuf<64> s_desc;
s_desc.Format( KImageDescription, i, &((*iDirList)[i].iName), &s_time );
aItems->AppendL( s_desc );
}
}
CleanupStack::PopAndDestroy( image_util );
CleanupStack::PopAndDestroy( image_data );
return;
}

The problems:
1. is there any problem with the cleanup or any kind of memory related problems
2. or it is that I need to have the media server running on.
3. or that I am using CPAlbImageUtil I need to derive from MPAlbImageFactoryObserver?
4. or that there is some problem with the listbox
5. is there some problem with the ownership of icons/icon array.
I am not able to figure out the problem. Please help.