×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    21

    RPointerArray and leaving

    Hi,

    I have some code such as:

    RPointerArray<CStuff> CClass::GetListOfStuffLC() {

    RPointerArray<CStuff> array=new (ELeave) RPointerArray<CStuff>(count);
    CleanupClosePushL(array);
    ...
    create and insert stuff into array


    return array;
    }

    The contents of the method can Leave, and it will also leave the array on the stack (since it will ALWAYS be used after a call to the function). The problem i am having is what happens if a leave occurs. CleanupClosePushL will only call Close() on the array, right? so how do the objects contained in the array get deleted? have i missed something?

    cheers

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: RPointerArray and leaving

    This seems to be an omisssion in the general areas of the close functions. If you look in MMFControllerPluginResolver.h there is an implementation of CleanupResetAndDestroyPushL which is what you should be using

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    21

    Re: RPointerArray and leaving

    thanks for the heads up.

    I solved it by making a class that extends one of the Dynamic Pointer Array classes, and added ResetAndDestroy to its destructor.

    If i run into any problems with this method, i'll give CleanupResetAndDestroyPushL a try

  4. #4
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: RPointerArray and leaving

    I would be careful with this approach as the Close will free the underlying pointer array and then the destructor will reset and destroy an empty array, which means leaks.

    I suggest you simulate a leave by User::Leave(KErrGeneral) and verify that all the pointers are in fact cleaned up.

    Also, looking at the code I am not sure why it is not compiling, though i put this down to typing errors, array is pointer to an RPointerArray, not an RPointerArray.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    21

    Re: RPointerArray and leaving

    Quote Originally Posted by Paul.Todd
    I would be careful with this approach as the Close will free the underlying pointer array and then the destructor will reset and destroy an empty array, which means leaks.

    I suggest you simulate a leave by User::Leave(KErrGeneral) and verify that all the pointers are in fact cleaned up.

    Also, looking at the code I am not sure why it is not compiling, though i put this down to typing errors, array is pointer to an RPointerArray, not an RPointerArray.
    I'm new to this symbian stuff, so previously I was fighting with the SDK over which kind of array to use. I'm now deriving my class from CArrayPtrSeg, so there is no Close to mess things up (fingers crossed that nothing else messes it up ). I just have to make sure I delete it when I've finished.

    Thanks for your replies

Posting Permissions

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