×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question How to deal with ALLOC PANIC?

    Hi all,

    I am developing an application for Nokia 5800.
    I came accross Alloc : 40c6230c panic On Exit button click
    Can anybody have any idea regarding this kind of panic?
    Or any hint regarding how to caught the exact point in code where this panic arises?
    Please help ASAP....

    Thanks and Regards,
    Kranti

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,533

    Re: How to deal with ALLOC PANIC?

    Check if all your memory allocations are freed. One of them could be instance variables whose memory can be freed in the destructor.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: How to deal with ALLOC PANIC?

    The way to deal with it is fixing it ;-)

    I'd urge you to search both the forum and wiki, as this topic has been raised (and answered) many times already.

  4. #4
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: How to deal with ALLOC PANIC?

    ALLOC Panic is nothing but a memory leak..
    An object created on the Heap has not been cleaned up properly...

    Check ur code for memory allocations and freeing them..
    Use HookLogger..It wil be very helpful in sorting out these problems..

  5. #5
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Re: How to deal with ALLOC PANIC?

    Hi Symbian_Neil,

    Thanks for reply ....

    1. I am facing this panic on emulator only and not on device On Exit button click.

    2. I have a gobalDataEngine class in my application. It's gobal pointer I am using through out the application (In all view and containers to fetch or store data).

    3. On Exit button click I use to destroy gobal pointer in AppUi destructor. But that way it gives me panic on device also.

    4. Then I deleted that global pointer before Exit() call in HandleCommandL() of AppUi >>
    Due to this change the application is working on device without any panic. But it raises alloc
    panic on emulator.

    5. I know that this not the correct way to destroy that global pointer ....
    but I think that AppUi's and GobalDataEngine's destructors are not invoking , and causing alloc
    panic.

    If the alloc panic is there on emulator then why it is not generating on device?

    Anyway I will again check for all memory allocations freed prperly or not ....

    Thanks and Regards,
    Kranti

  6. #6
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: How to deal with ALLOC PANIC?

    Hi,

    I think you should destory your global ptr in the class/function(like Main() ) where you are creating it.
    As you said, using global pointer is not right way to do this work, so might be worth putting some effort to have a relook at the implementation itself.
    Also better than shooting your code in worded statements, may be you can put a pseudo code on the forum for people to investigate problem. If you can post original code that would be even more useful.

    Regards
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  7. #7
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Re: How to deal with ALLOC PANIC?

    Hello,
    like deepchand86 said,
    go here:
    http://developer.symbian.com/main/to...gger/index.jsp

    install HookLogger
    watch presentation how to track memory leak.

    It will show you in which line there is memory leak causing your alloc and try to eliminate it.
    If you still will have problem with that paste here code which hooklogger shows as a leak and we will be able to help you.

    good luck

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

    Re: How to deal with ALLOC PANIC?

    An alloc panic does not show on a device because the mechanism for detecting it are only enabled indebug builds and not release builds.

    Anything to do with allocs literally has 5000 previous threads, you'll find all the information and more than you want if you look.

  9. #9
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Re: How to deal with ALLOC PANIC?

    Hi all,

    Thanks for user suggestions and hints. I will follow them, I am also trying to use HookLogger to find out exact panic point.

    Thanks And Regards,
    Kranti

  10. #10
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question Re: How to deal with ALLOC PANIC? -> If uses View-Container pair ...

    Hi all,

    I modified my code in following manner :

    1. Instantiated global class pointer in Document constructor :

    // ViewSwitchingDemo_5800Document.cpp

    GLDEF_D CGlobalClass* globalClass_p;
    .
    .
    .
    void CViewSwitchingDemo_5800Document::ConstructL()
    {
    globalClass_p = CGlobalClass::NewL();
    }

    CViewSwitchingDemo_5800Document::~CViewSwitchingDemo_5800Document()
    {
    if(globalClass_p)
    {
    delete globalClass_p;
    globalClass_p = NULL;
    }
    }
    . . . . .
    2. Using that in View as follows :


    GLREF_D CGlobalClass* globalClass_p;
    .
    .
    .

    void CViewSwitchingDemo_5800AppView::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
    {
    case EViewNext:
    {
    HBufC* usernameTxt = iAppViewContainer->iEdwinTestData->GetTextInHBufL();
    globalClass_p->test_HBuf_p = usernameTxt;
    .
    .
    .
    delete usernameTxt;

    }
    break;

    default:
    {
    AppUi()->HandleCommandL( aCommand );
    }
    break;

    }
    3. I globalClass .h and .cpp files are as follows :

    //GlobalClass.h

    class CGlobalClass : public CBase
    {
    public:
    //member var
    HBufC* test_HBuf_p;
    TBuf<10> test_TBuf;
    TInt iGlobal;
    ......
    }
    -----------------------------------------------------------------------

    //GlobalClass.cpp

    ........

    void CGlobalClass::ConstructL()
    {
    test_HBuf_p = HBufC::NewLC(10);
    CleanupStack::Pop();
    iGlobal = 10;

    }

    CGlobalClass::~CGlobalClass()
    {
    if(test_HBuf_p)
    {
    delete test_HBuf_p ;
    test_HBuf_p = NULL;
    }
    }


    .............


    4. If I use only TBuf or TInt through globalClass pointer there is no panic / error
    But If I use HBufC* in above mentioned manner, application raises panic on Exit.
    At point delete test_HBuf_p ; (I traced it using Just in time debugger)

    Panic : User:45 >>
    Explanation : This panic is raised by the Stop() member function of an active scheduler, a CActiveScheduler. Calling Stop() terminates the wait loop started by the most recent call to Start(). The panic is caused by a call to Stop() which is not matched by a corresponding call to Start().



    5. I wondered that same way the GobalClass(having HBuf*) working fine, If I use a single View class. And If I use View-Container it's giving me panic for destruction of global HBuf* ....!

    Can anybody guess any reason for this apposite behavior in these 2 cases???

    Please help if u have any hint regarding this.

    Thanks and Regards,
    Kranti

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: How to deal with ALLOC PANIC? -> If uses View-Container pair ...

    What you are quoting is the description of E32USER-CBase 45.
    If you have USER 45:
    Quote Originally Posted by SDK Help
    This panic is raised by the Free() and FreeZ() member functions of an RHeap. It is caused when the cell being freed overlaps the previous cell on the free list (i.e. the last cell on the free list with an address lower than the one being freed).
    which certainly appears to be a more proper error message when you are dealing with faulty memory management.

    And the reason is pretty obvious:
    HBufC* usernameTxt = iAppViewContainer->iEdwinTestData->GetTextInHBufL();
    globalClass_p->test_HBuf_p = usernameTxt;
    .
    .
    .
    delete usernameTxt
    test_HBuf_p is a pointer, so here is what you do:
    - the original HBufC allocated by "test_HBuf_p = HBufC::NewLC(10);" is lost, since you overwrite its pointer - by the way HBufC also has NewL, which is obviously more convenient if you are storing the result in a member variable
    - test_HBuf_p is going to point at usernameTxt
    - then you delete usernameTxt, so test_HBuf_p points to an invalid object
    - when you try to delete the object again, it obviously panics.
    In case of TBuf-s, your code works, because TBuf-s are not pointer, so whenever you write a=b, where both a and b are TBuf-s, the contents of b are copied into a.

  12. #12
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question Re: How to deal with ALLOC PANIC?

    Hi wizard_hu_,

    1. First of all I am sorry for the wrong quote regarding Panic (User 45).

    2. I got the point which u want to explain , thanks for that ,
    Accordingly I made following changes in code :
    // GlobalClass.cpp

    CGlobalClass::~CGlobalClass()
    {
    if(test_HBuf_p)
    {
    delete test_HBuf_p ;
    test_HBuf_p = NULL;
    }
    }

    void CGlobalClass::ConstructL()
    {

    iGlobal = 10;

    }
    ---------------------------------------------------------------------------------------------

    void CViewSwitchingDemo_5800AppView::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
    {
    case EViewNext:

    {

    HBufC* usernameTxt = iAppViewContainer->iEdwinTestData->GetTextInHBufL();
    globalClass_p->test_HBuf_p = usernameTxt;
    }
    .
    .
    .
    }


    3. Now there is no panic while "Exit".

    4. But I have one query >>
    HBufC* usernameTxt = iAppViewContainer->iEdwinTestData->GetTextInHBufL();


    How can I confirm about freeing the memory assigned to usernameTxt?

    If I am not wrong ... it's get freed when GlobalClass destructor invokes >>
    delete test_HBuf_p ;

    Please correct me if I am wrong?

    Thanks and Regards,
    Kranti

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: How to deal with ALLOC PANIC?

    Since you store the pointer "usernameTxt" into a member variable, you do not have to do anything with the variable "usernameTxt" at all, your test_HBuf_p will do the deletion in your destructor.
    Note that you practically do not need usernameTxt at all, you could simply write
    Code:
    globalClass_p->test_HBuf_p=iAppViewContainer->iEdwinTestData->GetTextInHBufL();
    There is no practical difference between the two (your "two-line" solution, and this "one-line" variant) - besides that you have a temporary local variable.

  14. #14
    Regular Contributor
    Join Date
    Sep 2008
    Location
    India
    Posts
    126

    Question Re: How to deal with ALLOC PANIC?

    Hi wizard_hu_,

    1. Thanks for clearing my doubt regarding freeing "usernameTxt".

    2. Regarding HBufC I read following description in SDK help :
    Using New()/L/LC there is one of the comman description point is
    "Data can, subsequently, be assigned into it using the assignment operators."

    3. About " operator=() "
    Copies data into this 16 bit heap descriptor replacing any existing data.

    4.
    globalClass_p->test_HBuf_p = iAppViewContainer->iEdwinTestData->GetTextInHBufL();
    5. That works fine for >> first "Next" button click >> "Exit".
    6. But if I press "Next" button 2 times and then press on "Exit" >> It again raises Alloc Panic on
    Exit.
    Eg. user entered wrong value first time >> "Next" button click will display msg "Invalid value" >> then second time user entered correct value >> but at this situation application "Exit" raises a Alloc Panic.

    7. What care should I take before assigning new value to
    "globalClass_p->test_HBuf_p" ?

    8. Please give me any hint, where I am going wrong while using this globalClass_p->test_HBuf_p...!

    Thanks and Regards,
    Kranti

  15. #15
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: How to deal with ALLOC PANIC?

    Pointers can be tricky things, and it is extremely important to learn their proper handling.
    Let us assume that we have HBufC pointers a and b
    Code:
    HBufC *a;
    HBufC *b;
    In this case *a and *b are HBufC objects (given that the pointers are initialized).
    And possible "="-s are:
    Code:
    a=b;
    In this case the pointer b is copied into pointer a, the two pointers are going to point at the same object - if a was pointing to something, that something is lost and we have a memory leak
    Code:
    *a=*b;
    in this case the operator= is invoked on object *a - since HBufC specifies an operator= accepting any other descriptor (of the same 8/16 bit width), object *b will be accepted too. The result is that content of object *b is going to be copied into object *a - two pointers pointing two object, having same content, momentarily.

Similar Threads

  1. CImageDecoder Alloc Panic
    By coolblues5000 in forum Symbian
    Replies: 7
    Last Post: 2008-11-10, 06:09
  2. Using Bluetooth serial port in MIDlets (nokia 9500 issue)
    By orsteglasy in forum Mobile Java Networking & Messaging & Security
    Replies: 11
    Last Post: 2007-10-07, 21:49
  3. ALLOC 0 panic -- CDesC16ArrayFlat leaks
    By bnvaikos in forum Symbian
    Replies: 5
    Last Post: 2007-07-09, 10:21
  4. Strange ALLOC Panic (Symbian 9)
    By isemenov in forum Symbian
    Replies: 6
    Last Post: 2006-12-21, 10:28
  5. ALLOC Panic found, Please help...
    By yogesh14 in forum Symbian User Interface
    Replies: 22
    Last Post: 2006-11-27, 13:13

Posting Permissions

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