×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    136

    Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    Hello,
    I am getting some strange problem ...
    Please find attached code ... I am getting KERN EXEC 3 on Red color line ... any help Y this is happening

    Code:
    void CContactForTestAppUi::AddContactsIntoListArrayL()
    {
      iListBoxItems = new (ELeave) CDesCArrayFlat(2);
      iContactIDArray = new (ELeave) CArrayFixFlat<TInt>(2);
      IsInGroup =  new (ELeave) CArrayFixFlat<TInt>(2);
    //open the default contacts database
    CContactDatabase* contactsDb = CContactDatabase::OpenL();
    CleanupStack::PushL(contactsDb);
    
    contactsDb->SetDbViewContactType(KUidContactCard);
    CArrayFix<CContactDatabase::TSortPref>* sortOrder =
    		new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(2);
    CleanupStack::PushL(sortOrder);
    CContactDatabase::TSortPref familyNamePref(KUidContactFieldFamilyName, CContactDatabase::TSortPref::EAsc);
    sortOrder->AppendL(familyNamePref);
    CContactDatabase::TSortPref givenNamePref(KUidContactFieldGivenName, CContactDatabase::TSortPref::EAsc);
    sortOrder->AppendL(givenNamePref);
    contactsDb->SortL(sortOrder); // Takes ownership of sortOrder.
    
    //sortOrder->Reset();
    //delete sortOrder;
    
    const CContactIdArray* contactIds = contactsDb->SortedItemsL();
    
    TInt totalContacts = (*contactIds).Count();
    //CContactGroup* cgroup;
    //cgroup = iCPBEngine->OpenContactGroupL(iGroupID);
    CContactGroup* cgroup = static_cast<CContactGroup*>(contactsDb->OpenContactL( iGroupID));
    CleanupStack::PushL(cgroup);
    for (TInt index = 0; index< totalContacts; index ++)
    {
    	
    	CContactItem* contact = NULL;
    	contact = contactsDb->OpenContactL((*contactIds)[index]);
    	CleanupStack::PushL( contact );
    	TInt a = contact->Id();
    	iContactIDArray->AppendL(a);
    	TBool setMark = cgroup->ContainsItem(a);
    	if (setMark)
    	{
    		//iListBox->View()->SelectItemL( index );
    		iIsInGroup->AppendL(index);
    	}
    	
    	{
    	CContactItemFieldSet& fieldSet = contact->CardFields();
    	// Get first name
    	__UHEAP_MARK;
    	
    	
    	HBufC* listItemName = HBufC::NewL(128);
    	listItemName->Des().Zero();
    	listItemName->Des().Copy(_L("1\t"));
    	TInt findpos( fieldSet.Find( KUidContactFieldGivenName ) );
    	// Check that the first name field is actually there.
    	if ( (findpos > -1) || (findpos >= fieldSet.Count()) )
    	{
    		CContactItemField& firstNameField = fieldSet[findpos];
    		CContactTextField* firstName = firstNameField.TextStorage();
    		//TPtrC ptrC = firstName->StandardTextLC();
    		HBufC* firstNameBuf = NULL;
    		firstNameBuf = firstName->Text().AllocLC();
    		listItemName->Des().Append(firstNameBuf->Des());
    		listItemName->Des().Append(_L(" "));
    		CleanupStack::PopAndDestroy(firstNameBuf);//ptrC
    		delete firstName;
    	}
    	// Get last name
    	findpos = fieldSet.Find( KUidContactFieldFamilyName );
    	// Check that the last name field is actually there.
    	if ( (findpos > -1) || (findpos >= fieldSet.Count()) )
    	{
    		CContactItemField& lastNameField = fieldSet[ findpos ];
    		CContactTextField* lastName = lastNameField.TextStorage();
    		HBufC* lastNameBuf = NULL;
    		//TPtrC ptrC = lastName->StandardTextLC();
    		lastNameBuf = lastName->Text().AllocLC();
    		listItemName->Des().Append(lastNameBuf->Des());
    		CleanupStack::PopAndDestroy(lastNameBuf);//ptrC
    		delete lastName;
    	}
    	if (listItemName->Des().Length()>3)
    	{
    	
    	}
    	else
    	{
    		listItemName->Des().Append(_L("(Unnamed)"));
    	}
    	
    	delete listItemName;
    		__UHEAP_MARKEND;// No leak till this 
    	contactsDb->CloseContactL(contact->Id());
    	}
    
    	
    	CleanupStack::PopAndDestroy(contact);
    	
    }
    
    contactsDb->CloseContactL(iGroupID);
    CleanupStack::PopAndDestroy();//cgroup
    CleanupStack::Pop(sortOrder);
    CleanupStack::PopAndDestroy(); //contactsDb,
    }
    // End of File
    Regards
    Sawpnil

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    I thnk you just need to call pop on this item as you made the push rest of the work is done by closecontactL();

    except thhis you haven't done any memory allocation from your side.

    CleanupStack::Pop(contact);
    Regards,
    Shafali

  3. #3
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    136

    Re: Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    Quote Originally Posted by shafali gupta View Post
    I thnk you just need to call pop on this item as you made the push rest of the work is done by closecontactL();

    except thhis you haven't done any memory allocation from your side.

    CleanupStack::Pop(contact);
    Hello
    Thanks for your reply . I am still not clear.. If I just Pop the Contact object then it will cause memory leak , isnt it ??
    Actually I am calling this function on view activation in multiview application from ContructL of Container ... I am facing problem of memory leak... Application gives Memory Full error on 7- 8th call to the view activation (with number of contacts = 160) but if I reduced the no. of contact to 10 then it will not Occur for many items ..i tested for 20 -25 times NO error since ..so I concluded this is the only function where it is loading contacts in List box.
    Being trying to delete contact object, I am facing this problem ... If I am just POP the contact then it will cause memory leak btw for loop.

    Any Pointers for the same ???
    Attached code for reference

    Code:
    void CContactForTestAppUi::AddContactsIntoListArrayL()
    {
      iListBoxItems = new (ELeave) CDesCArrayFlat(2);
      iContactIDArray = new (ELeave) CArrayFixFlat<TInt>(2);
      IsInGroup =  new (ELeave) CArrayFixFlat<TInt>(2);
    //open the default contacts database
    CContactDatabase* contactsDb = CContactDatabase::OpenL();
    CleanupStack::PushL(contactsDb);
    
    contactsDb->SetDbViewContactType(KUidContactCard);
    CArrayFix<CContactDatabase::TSortPref>* sortOrder =
    		new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(2);
    CleanupStack::PushL(sortOrder);
    CContactDatabase::TSortPref familyNamePref(KUidContactFieldFamilyName, CContactDatabase::TSortPref::EAsc);
    sortOrder->AppendL(familyNamePref);
    CContactDatabase::TSortPref givenNamePref(KUidContactFieldGivenName, CContactDatabase::TSortPref::EAsc);
    sortOrder->AppendL(givenNamePref);
    contactsDb->SortL(sortOrder); // Takes ownership of sortOrder.
    
    //sortOrder->Reset();
    //delete sortOrder;
    
    const CContactIdArray* contactIds = contactsDb->SortedItemsL();
    
    TInt totalContacts = (*contactIds).Count();
    //CContactGroup* cgroup;
    //cgroup = iCPBEngine->OpenContactGroupL(iGroupID);
    CContactGroup* cgroup = static_cast<CContactGroup*>(contactsDb->OpenContactL( iGroupID));
    CleanupStack::PushL(cgroup);
    for (TInt index = 0; index< totalContacts; index ++)
    {
    	__UHEAP_MARK;
    	CContactItem* contact = NULL;
    	contact = contactsDb->OpenContactL((*contactIds)[index]);
    	CleanupStack::PushL( contact );
    	TInt a = contact->Id();
    	iContactIDArray->AppendL(a);
    	TBool setMark = cgroup->ContainsItem(a);
    	if (setMark)
    	{
    		//iListBox->View()->SelectItemL( index );
    		iIsInGroup->AppendL(index);
    	}
    	
    	{
    	CContactItemFieldSet& fieldSet = contact->CardFields();
    	// Get first name
    	__UHEAP_MARK;
    	
    	
    	HBufC* listItemName = HBufC::NewL(128);
    	listItemName->Des().Zero();
    	listItemName->Des().Copy(_L("1\t"));
    	TInt findpos( fieldSet.Find( KUidContactFieldGivenName ) );
    	// Check that the first name field is actually there.
    	if ( (findpos > -1) || (findpos >= fieldSet.Count()) )
    	{
    		CContactItemField& firstNameField = fieldSet[findpos];
    		CContactTextField* firstName = firstNameField.TextStorage();
    		//TPtrC ptrC = firstName->StandardTextLC();
    		HBufC* firstNameBuf = NULL;
    		firstNameBuf = firstName->Text().AllocLC();
    		listItemName->Des().Append(firstNameBuf->Des());
    		listItemName->Des().Append(_L(" "));
    		CleanupStack::PopAndDestroy(firstNameBuf);//ptrC
    		delete firstName;
    	}
    	// Get last name
    	findpos = fieldSet.Find( KUidContactFieldFamilyName );
    	// Check that the last name field is actually there.
    	if ( (findpos > -1) || (findpos >= fieldSet.Count()) )
    	{
    		CContactItemField& lastNameField = fieldSet[ findpos ];
    		CContactTextField* lastName = lastNameField.TextStorage();
    		HBufC* lastNameBuf = NULL;
    		//TPtrC ptrC = lastName->StandardTextLC();
    		lastNameBuf = lastName->Text().AllocLC();
    		listItemName->Des().Append(lastNameBuf->Des());
    		CleanupStack::PopAndDestroy(lastNameBuf);//ptrC
    		delete lastName;
    	}
    	if (listItemName->Des().Length()>3)
    	{
    	
    	}
    	else
    	{
    		listItemName->Des().Append(_L("(Unnamed)"));
    	}
    	
    	delete listItemName;
    		__UHEAP_MARKEND;// No leak till this 
    	contactsDb->CloseContactL(contact->Id());
    	}
    
    	CleanupStack::Pop(contact); //As suggested by YOU
    	//CleanupStack::PopAndDestroy(contact); // if uncommented this line by commenting above POP(contact)line..KERN EXE 3 
    	__UHEAP_MARKEND;// mem leak 
    	
    }
    
    contactsDb->CloseContactL(iGroupID);
    CleanupStack::PopAndDestroy();//cgroup
    CleanupStack::Pop(sortOrder);
    CleanupStack::PopAndDestroy(); //contactsDb,
    }
    // End of File
    Please help for the same
    Thanks in advance...

    Regards
    Swapnil

  4. #4
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    Quote Originally Posted by swapnilb83 View Post
    Hello
    Thanks for your reply . I am still not clear.. If I just Pop the Contact object then it will cause memory leak , isnt it ??
    Actually I am calling this function on view activation in multiview application from ContructL of Container ... I am facing problem of memory leak... Application gives Memory Full error on 7- 8th call to the view activation (with number of contacts = 160) but if I reduced the no. of contact to 10 then it will not Occur for many items ..i tested for 20 -25 times NO error since ..so I concluded this is the only function where it is loading contacts in List box.
    Being trying to delete contact object, I am facing this problem ... If I am just POP the contact then it will cause memory leak btw for loop.

    Any Pointers for the same ???
    Attached code for reference

    Code:
    void CContactForTestAppUi::AddContactsIntoListArrayL()
    {
      iListBoxItems = new (ELeave) CDesCArrayFlat(2);
      iContactIDArray = new (ELeave) CArrayFixFlat<TInt>(2);
      IsInGroup =  new (ELeave) CArrayFixFlat<TInt>(2);
    //open the default contacts database
    CContactDatabase* contactsDb = CContactDatabase::OpenL();
    CleanupStack::PushL(contactsDb);
    
    contactsDb->SetDbViewContactType(KUidContactCard);
    CArrayFix<CContactDatabase::TSortPref>* sortOrder =
    		new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(2);
    CleanupStack::PushL(sortOrder);
    CContactDatabase::TSortPref familyNamePref(KUidContactFieldFamilyName, CContactDatabase::TSortPref::EAsc);
    sortOrder->AppendL(familyNamePref);
    CContactDatabase::TSortPref givenNamePref(KUidContactFieldGivenName, CContactDatabase::TSortPref::EAsc);
    sortOrder->AppendL(givenNamePref);
    contactsDb->SortL(sortOrder); // Takes ownership of sortOrder.
    
    //sortOrder->Reset();
    //delete sortOrder;
    
    const CContactIdArray* contactIds = contactsDb->SortedItemsL();
    
    TInt totalContacts = (*contactIds).Count();
    //CContactGroup* cgroup;
    //cgroup = iCPBEngine->OpenContactGroupL(iGroupID);
    CContactGroup* cgroup = static_cast<CContactGroup*>(contactsDb->OpenContactL( iGroupID));
    CleanupStack::PushL(cgroup);
    for (TInt index = 0; index< totalContacts; index ++)
    {
    	__UHEAP_MARK;
    	CContactItem* contact = NULL;
    	contact = contactsDb->OpenContactL((*contactIds)[index]);
    	CleanupStack::PushL( contact );
    	TInt a = contact->Id();
    	iContactIDArray->AppendL(a);
    	TBool setMark = cgroup->ContainsItem(a);
    	if (setMark)
    	{
    		//iListBox->View()->SelectItemL( index );
    		iIsInGroup->AppendL(index);
    	}
    	
    	{
    	CContactItemFieldSet& fieldSet = contact->CardFields();
    	// Get first name
    	__UHEAP_MARK;
    	
    	
    	HBufC* listItemName = HBufC::NewL(128);
    	listItemName->Des().Zero();
    	listItemName->Des().Copy(_L("1\t"));
    	TInt findpos( fieldSet.Find( KUidContactFieldGivenName ) );
    	// Check that the first name field is actually there.
    	if ( (findpos > -1) || (findpos >= fieldSet.Count()) )
    	{
    		CContactItemField& firstNameField = fieldSet[findpos];
    		CContactTextField* firstName = firstNameField.TextStorage();
    		//TPtrC ptrC = firstName->StandardTextLC();
    		HBufC* firstNameBuf = NULL;
    		firstNameBuf = firstName->Text().AllocLC();
    		listItemName->Des().Append(firstNameBuf->Des());
    		listItemName->Des().Append(_L(" "));
    		CleanupStack::PopAndDestroy(firstNameBuf);//ptrC
    		delete firstName;
    	}
    	// Get last name
    	findpos = fieldSet.Find( KUidContactFieldFamilyName );
    	// Check that the last name field is actually there.
    	if ( (findpos > -1) || (findpos >= fieldSet.Count()) )
    	{
    		CContactItemField& lastNameField = fieldSet[ findpos ];
    		CContactTextField* lastName = lastNameField.TextStorage();
    		HBufC* lastNameBuf = NULL;
    		//TPtrC ptrC = lastName->StandardTextLC();
    		lastNameBuf = lastName->Text().AllocLC();
    		listItemName->Des().Append(lastNameBuf->Des());
    		CleanupStack::PopAndDestroy(lastNameBuf);//ptrC
    		delete lastName;
    	}
    	if (listItemName->Des().Length()>3)
    	{
    	
    	}
    	else
    	{
    		listItemName->Des().Append(_L("(Unnamed)"));
    	}
    	
    	delete listItemName;
    		__UHEAP_MARKEND;// No leak till this 
    	contactsDb->CloseContactL(contact->Id());
    	}
    
    	CleanupStack::Pop(contact); //As suggested by YOU
    	//CleanupStack::PopAndDestroy(contact); // if uncommented this line by commenting above POP(contact)line..KERN EXE 3 
    	__UHEAP_MARKEND;// mem leak 
    	
    }
    
    contactsDb->CloseContactL(iGroupID);
    CleanupStack::PopAndDestroy();//cgroup
    CleanupStack::Pop(sortOrder);
    CleanupStack::PopAndDestroy(); //contactsDb,
    }
    // End of File
    Please help for the same
    Thanks in advance...

    Regards
    Swapnil
    try deleting the object this way
    if(contact)
    {
    delete contact;
    contact=NULL;
    }
    Regards,
    Shafali

  5. #5
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    136

    Re: Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    Quote Originally Posted by shafali gupta View Post
    try deleting the object this way
    if(contact)
    {
    delete contact;
    contact=NULL;
    }
    Hi
    tried doing this ...

    Code:
    CleanupStack::Pop(contact);
    	if (contact)
    		{
    			delete contact; ///KERN EXEC 3 on this line 
    			contact = NULL;
    		}
    I Am fade up with this now ... it is going inside the If (contact ) and giving panic on delete contact; line []

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    First guess: personally I would not delete pointers I get from non-L methods (with some obvious exceptions, like CXy::New or Alloc), because those pointers are most probably still owned by the given object. CContactTextField::TextStorage seems to fall into this category, but there may be others too.

  7. #7
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    136

    Re: Help On Contact List Name Population Function ..KERN EXEC ..Code Attached

    Quote Originally Posted by wizard_hu_ View Post
    First guess: personally I would not delete pointers I get from non-L methods (with some obvious exceptions, like CXy::New or Alloc), because those pointers are most probably still owned by the given object. CContactTextField::TextStorage seems to fall into this category, but there may be others too.
    Hello Wizard,
    Thanks for the pointer... It works after this. Thanks you very much. I can sleep tonite

Similar Threads

  1. J2ME and contact list
    By morphine_titan in forum Mobile Java General
    Replies: 7
    Last Post: 2009-01-06, 07:49
  2. Replies: 2
    Last Post: 2007-10-05, 20:40
  3. Help! Basic TCP connection - Source code attached
    By dineshguru in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2002-10-10, 05:01
  4. Showing and accesing contact list library
    By djorge in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-09-25, 11:01
  5. Problem with Nokia D211 Linux Drivers
    By fiveam in forum Multimodecards
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×