Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Aug 2010

    Does CleanupStack::PopandDestroy(TAny*) do a recursive delete?


    I wanted to clarify this point. Assuming a class definition like this:

    class A
    B *b;
    C * c;
    D *d;
    static NewL();

    A* a = A::NewL();
    a->b = B::NewL();
    and so each object member within a is created.

    //do some operation


    Will the pop and destroy operation automatically reclaim the memory allocated for the member objects as well?

    Please clarify.


  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003

    Re: Does CleanupStack::PopandDestroy(TAny*) do a recursive delete?

    Nope, with that example a simple free for the pointer A would be performed. Thus you should first derive the class A from CBase, and then also implement a destructor on it that takes care of freeing any intenal items it might have. Also you should have the B/C/D as private members and handle costruction of them through public functions of the class A.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Budapest, Hungary

    Re: Does CleanupStack::PopandDestroy(TAny*) do a recursive delete?

    If you check the CleanupStack::PushL variants, you will see that there is a generic one accepting TAny*, and a specific one accepting CBase*. The difference between the two is that on PopAndDestroy TAny* is going to be User::Free-d at the end, while CBase* is going to be delete-d (so its destructor gets executed and it can free/close/delete/etc. its member variables).

  4. #4
    Super Contributor
    Join Date
    Mar 2008

    Re: Does CleanupStack::PopandDestroy(TAny*) do a recursive delete?

    Just to add to wizard_hu's post, there is another PushL(TCleanupItem anItem) where TCleanupItem encapsulates a cleanup operation and an object on which the operation is to be performed.

Similar Threads

  1. confused on CleanupStack::PopAndDestroy
    By aliangg in forum Symbian
    Replies: 14
    Last Post: 2008-11-03, 09:12
  2. Replies: 9
    Last Post: 2007-03-16, 11:03
  3. CleanupStack::PopAndDestroy() stops me!!
    By symbee in forum Symbian
    Replies: 32
    Last Post: 2006-09-01, 14:30
  4. Replies: 5
    Last Post: 2005-08-18, 08:51
  5. CleanupStack::Pop and CleanupStack::PopAndDestroy
    By julppoupou in forum Symbian
    Replies: 1
    Last Post: 2003-07-14, 06:54

Posting Permissions

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