×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Feb 2008
    Posts
    252

    How to clean memory of a secondary thread from main thread

    Hi all,

    I am creating the obj of a class from a secondary thread , I want to cleanup all the memory assigned for this obj from main thread.

    but all object pointer comes null when i am trying to delete from main thread (so i couldnot freee the memory only i can kill the thread). So does thread automatically clean all the resources allocated in my secondary thread when i kill that thread if no how to clean these resources .

    Please suggest.

    Best regard

    Deepak

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: How to clean memory of a secondary thread from main thread

    It also depends on the heap which the secondary thread uses. If it has an own "automatic" heap (RThread::Create with aHeapMinSize, aHeapMaxSize), it it most probably deallocated when the thread exits.
    However if you provide a heap manually (RThread::Create with RAllocator), that heap survives the death of the thread.

  3. #3
    Regular Contributor
    Join Date
    Feb 2008
    Posts
    252

    Re: How to clean memory of a secondary thread from main thread

    Quote Originally Posted by wizard_hu_ View Post
    It also depends on the heap which the secondary thread uses. If it has an own "automatic" heap (RThread::Create with aHeapMinSize, aHeapMaxSize), it it most probably deallocated when the thread exits.
    However if you provide a heap manually (RThread::Create with RAllocator), that heap survives the death of the thread.
    Thanks for ur reply, I have not made any threading aplication on symbian before . I am following a wiki link.My code is as below

    Code:
    	const TInt KStackSize = 16384;
    	HBufC* threadName = HBufC::NewLC(KMaxFileName);
    	TPtr ptr = threadName->Des();
    
    	User::LeaveIfError(iThread.Create(
    	                    *threadName,
    	                    ThreadFunction,
    	                    KStackSize,
    	                    NULL,
    	                    this));
    and this is my thread clean up func which i am calling from destructor
    Code:
    void Cabc::DoThreadCleanUp()
    {
    	iThread.LogonCancel(iStatus);
    	iThread.Kill(KErrCancel);
    	iThread.Close();
    }
    and my destructor is as below
    Code:
    	DoThreadCleanUp();
    	def->Cleanup(); //it clean all object allocated inside thread
    but here "def" come null always so I have seen that it never goes to any destructor so how can i sure that it cleans the memory allocated (i have made some new cclass )in the secondary therad.

    Thanks

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: How to clean memory of a secondary thread from main thread

    Why do you want to kill your thread this way actually? (What does your thread do?)
    And why would "def" contain anything else than NULL?

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

    Re: How to clean memory of a secondary thread from main thread

    You don't show what def is or what Cleanup() does.



    Do you even need to use threads?

Similar Threads

  1. S60 5th ed emulator startup failed
    By hony in forum Symbian Tools & SDKs
    Replies: 8
    Last Post: 2009-08-11, 21:12
  2. emulator startup failed
    By hony in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-11-11, 06:07
  3. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29
  4. 9210 and 9210i java memory
    By allams in forum Mobile Java General
    Replies: 0
    Last Post: 1970-01-01, 02:00
  5. Thread and Memory
    By glevernier in forum Mobile Java General
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

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