Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor ruchirvasavada's Avatar
    Join Date
    Mar 2007
    Location
    B'lore
    Posts
    72
    Hi...

    I am having some memory leak in my app and I fear that the object of CPbkContactEngine is acting as one of the potential memory leaks. The object is created as follows :

    CPbkContactEngine *contactEngine = CPbkContactEngine::NewL();

    If I put heap memory check before and after this statement, I can see around 55KB of mem allocation on heap.

    At the end of the function I call the destructor of the class by using delete operator, and again check the heap memory but the memory previoulsy allocated doesnt get de-allocated.

    Does anyone have any idea..??

    Ruchir
    Last edited by ruchirvasavada; 2007-06-04 at 11:17.

  2. #2
    Regular Contributor ruchaitu's Avatar
    Join Date
    Oct 2004
    Location
    India
    Posts
    138
    Obviously, there will be a difference in heap mem usage becoz you have created a new object,
    what is more troubling is mem difference even after deleting the object,
    can you give more details about what operations did you perform between
    from object creation and object deletion.
    then it will be easy to diagnise.
    regards,
    - kc.

  3. #3
    Regular Contributor ruchirvasavada's Avatar
    Join Date
    Mar 2007
    Location
    B'lore
    Posts
    72
    Dear KC,

    Thanks for the reply!

    This is what I am doing in my app :

    1) there is a function which takes any number entered by user
    2) find, if the entry for that number is available in local contacts
    3) if match is found, then retrieve the name of the contact number
    4) now dial the number displaying that name in GUI
    5) if match is not found then display the number in GUI and no name

    now, if we talk in terms of coding,

    1) CPbkContactEngine *contactEngine = CPbkContactEngine::NewL();
    -> initialise the contact engine

    2) CContactIdArray* matches = contactEngine->MatchPhoneNumberL(*number, len_number);
    -> find all the matches found for the number that returns an array, as can be seen

    3) CPbkContactItem* item = contactEngine->OpenContactL((*matches)[0]);
    -> pick up the first entry from the array of matched items

    4) TPbkContactItemField* field = item->FindField(EPbkFieldIdFirstName);
    -> pick up the name from the item.

    5) finally return the name that was retrieved.

    I have taken utmost care of destroying all the HBufCs that are used.

    Before exiting the function, I am resetting the CContactIdArray object and then calling CleanupStack::PopAndDestroy(), which will call the desturctor, and finally deleting the CPbkContactEngine object. In-between I am also deleting the item & field objects.

    Looking forward for your suggestions..

    Thanks,
    Ruchir

  4. #4
    Regular Contributor ruchaitu's Avatar
    Join Date
    Oct 2004
    Location
    India
    Posts
    138
    well, if the item and engine are deleted then who is leaking the mem,
    are you gettting a alloc panic or you are checking memory with macros.

    if your code is not under a Non diclosure agreement, \
    can you paste the code here, i mean you already pasted it, i didnt see the deletion and 'pop and destroy' code any where, so just assuming that few more lines needs to be posted.

    also, search the internet there are quite a few docs available which have more than one way of solving mem leaks. like finding out who exactly leaked it.

    cheers,
    -kc

  5. #5
    Regular Contributor ruchirvasavada's Avatar
    Join Date
    Mar 2007
    Location
    B'lore
    Posts
    72
    Thanks for reply...

    Actually the code is not to be disclosed... and so would not be able to put much part of it, but as far as destruction is concerned, I have used CleanupStack::PopAndDestroy() calls at the end of the functions, like :

    CleanupStack::PopAndDestroy(contactEngine);
    CleanupStack::PopAndDestroy(phoneNumberToLookup);
    CleanupStack::PopAndDestroy(eightBitTemp);

    One thing that is attracting me is, the size that gets allocated for the first time is as much as 55K and then if I come to this function the next time onwards, the size would be around two pages (2*4096).

    I dont get any Panic, as far as I am within the heap size limit. I have used User::RHeap().Size() call to know the heap size after almost every allocation and deallocation (supposed to be ) code..

    Thanks
    Ruchir
    Ruchir

  6. #6
    Regular Contributor ruchaitu's Avatar
    Join Date
    Oct 2004
    Location
    India
    Posts
    138
    No Alloc Panics

    then i cannot say whether there is any leak or not?

    1. get Heap size
    2. execute ur code
    3. get Heap size again.

    If you are saying that mem is leaked becoz heap size in step 1 and step 2 does not match, then we need to check whether your code is allocating mem for any member variables or not.

    There can be a situation where heap size in above case differs frm 1 and 2, but the extra mem is deallocated some where else.

    If the above said case is not correct then only one option left.

    comment the entire code,
    uncomment one by one, i mean firt uncomment the
    creation and deletion of contact object
    and so on....

    check heap size in every step...and lets see whether this will uncover the problem or not.

    - kc

  7. #7
    Regular Contributor teemukurppa's Avatar
    Join Date
    Sep 2006
    Location
    Helsinki
    Posts
    109
    If you don't get ALLOC panics, then your code is quite likely safe.

    HEAP size checks in your code can indicate leak, even if there is not, because calls to library functions can allocate and initialize some app-framework level singletons that are released only when app is closed.
    Teemu Kurppa
    Blog: http://dirtyaura.org/blog

  8. #8
    Regular Contributor ruchirvasavada's Avatar
    Join Date
    Mar 2007
    Location
    B'lore
    Posts
    72
    Oh... i c... that's interesting behaviour.... Thanks for sharing that...
    Ruchir

  9. #9
    Registered User ntb's Avatar
    Join Date
    Feb 2007
    Posts
    6
    I've faced the same problems. After a few try, i found out that CPbkContactEngine::Static() works perfectly, without memory leak.

  10. #10
    Regular Contributor zhangjunhua's Avatar
    Join Date
    Dec 2007
    Posts
    196
    Quote Originally Posted by ntb View Post
    I've faced the same problems. After a few try, i found out that CPbkContactEngine::Static() works perfectly, without memory leak.
    but CPbkContactEngine::Static() return null,why?Can you tell me ?

Similar Threads

  1. Replies: 2
    Last Post: 2007-10-05, 20:40
  2. Audio Input Stream on N80
    By tkaihock in forum Symbian Media (Closed)
    Replies: 9
    Last Post: 2006-06-30, 09:15
  3. The correct meaning of MAX JAR size
    By bigrio in forum Mobile Java General
    Replies: 1
    Last Post: 2004-11-16, 10:30
  4. The correct meaning of MAX JAR size
    By bigrio in forum Mobile Java General
    Replies: 0
    Last Post: 2004-11-13, 11:03
  5. User break point error in Grid
    By ag24master in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-08-07, 08:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved