×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    84

    CleanupClosePushL in ConstructL

    Hi all!

    Does it make sense to use CleanupClosePushL on a handle in the ConstructL method of an active object?

    Or the handle has to be closed in the RunError() method?

    MrAlt

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    282

    Re: CleanupClosePushL in ConstructL

    If the handle is scoped local to the ConstructL method then it not only makes sense its essential. Otherwise you may leak handles of your contructL leaves in between.

    Remember RunError is only called when your RunL leaves. There can be perfect valid control flows in you code where RunError never gets called. So for me the best place to close your handles is your CActive's destructors. However you can optimize your code to close handles much before.

    Hope that helps,
    VJ

  3. #3
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    58

    Re: CleanupClosePushL in ConstructL

    From the way the question is asked I suspect you are not 100% clear on the use of the cleanupstack and its role in deletion/closing.
    I think you have another misunderstanding behind the surface leading to this question, which by the way doesn't totally make sense as the location on where you close something is not releated to the use of the cleanupstack or constructl.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: CleanupClosePushL in ConstructL

    Otherwise the rule is simple: you never put a member variable on the Cleanup Stack, because you can delete/Close/Release/etc. it in the destructor.

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    84

    Re: CleanupClosePushL in ConstructL

    Thanks for your help vaibhavjain!

    I was talking about a handle local to the object, not just to the method. For example a P&S handle:

    First without CleanupClosePushL:
    - I create the handle in the ConstructL of my active object
    - For any reason, RunL leaves.
    - In RunError: I suppose that I have to close this handle.

    Now with CleanupClosePushL:
    - I create the handle in the ConstructL of my active object
    - I put it on the cleanup stack with CleanupClosePushL
    - For any reason, RunL leaves.
    - In RunError: I don't have to close it there?

    The Cynic, you're right, I'm not 100% clear with cleanupstack and Co, that's why I ask this question In fact, I'd like to understand how it works in an active object context (rather than local to a method).


    vaibhavjain seems to say that in fact it's better to avoid to leave in RunL. I think it's maybe the best solution

  6. #6
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    84

    Re: CleanupClosePushL in ConstructL

    Quote Originally Posted by wizard_hu_ View Post
    Otherwise the rule is simple: you never put a member variable on the Cleanup Stack, because you can delete/Close/Release/etc. it in the destructor.
    Yes, you're right. I surely ask myself too many questions, the handle will be closed with the call to "delete".

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    282

    Re: CleanupClosePushL in ConstructL

    Adding on to that it can be disastrous if you do cleanup of your class members in your contructl. If you have a leave in constructl and try to delete your instance variable in you destructors again then you may see the famous Kern Exec 3 panic. Thats beacuse cleanup stack has already deleted those members.

    PS: In case of handles the kern exec 3 is at times replaced my kern exec 0.

    So i will lay emphasis on the rule mentioned by wizard_hu "rule is simple: you never put a member variable on the Cleanup Stack, because you can (should) delete/Close/Release/etc. it in the destructor."

    Hope that helps,
    VJ

  8. #8
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: CleanupClosePushL in ConstructL

    You should do your deletions and handle closing etc. in the destructor, with an active object having a RunError() method doesn't change that rule.

  9. #9
    Regular Contributor
    Join Date
    Apr 2008
    Location
    India
    Posts
    477

    Re: CleanupClosePushL in ConstructL

    so simple protocols which may be follow:

    1. Delete the member variables in ~() only;
    2. Use CleanUpStack for local heap object if you are calling leavable function after creation of it in any local scope.
    3. RunError() is nothing to do with cleanup of the class its all about the info which AO f/w gives that code in RunL() is paniced due to some reason and what to do next.

  10. #10
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    84

    Re: CleanupClosePushL in ConstructL

    Thank you All for your answers!

    Things are clearer now.

Similar Threads

  1. AppUi 's ConstructL
    By arungupta_2jan in forum Symbian C++
    Replies: 10
    Last Post: 2011-02-21, 17:55
  2. Occurrence of 'CleanupClosePushL'
    By mittali in forum Symbian C++
    Replies: 22
    Last Post: 2009-05-16, 07:59
  3. Form not displayed when is created in Container ConstructL
    By redbart in forum Symbian User Interface
    Replies: 2
    Last Post: 2008-04-01, 10:30
  4. Replies: 3
    Last Post: 2007-07-19, 09:54
  5. Replies: 4
    Last Post: 2007-05-24, 04:06

Posting Permissions

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