C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

problem delete class object contained thread

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
morz
Guest





PostPosted: Wed Jul 26, 2006 9:11 am    Post subject: problem delete class object contained thread Reply with quote



classA
{
public:

thirdPartyThreadLibrary myThread;

void Run()
{
myThread.exec(); // created new thread and run on background.
}

};


****LOT OF FUNCTION HERE****

//----------------------------------------------------------------
void myGUIFunctionNamed_Execute()
{
classA * objectA = new classA();
objectA->Run();
delete objectA <---- here is my big problem.If i put this
line, surely myThread in classA
deleted.auto_ptr
also cannot help.If i dont put this line,
my code is perfectly run,but of course
memory leaked.
}
//----------------------------------------------------------------


****LOT OF FUNCTION HERE****


My problem is my object of thread inside classA and object of classA
inside function myGUIFunctionNamed_Execute().I want
myGUIFunctionNamed_Execute()
return immediately after i called it,but i dont no how to delete
object(objectA)
inside this function.My idea is to use auto pointer but when i using
this line ;

auto_ptr<classA> objectA(new classA());

is no luck. Sad
Back to top
Ian Collins
Guest





PostPosted: Wed Jul 26, 2006 9:11 am    Post subject: Re: problem delete class object contained thread Reply with quote



morz wrote:
Quote:
classA
{
public:

thirdPartyThreadLibrary myThread;

void Run()
{
myThread.exec(); // created new thread and run on background.
}

};


****LOT OF FUNCTION HERE****

//----------------------------------------------------------------
void myGUIFunctionNamed_Execute()
{
classA * objectA = new classA();
objectA->Run();
delete objectA <---- here is my big problem.If i put this
line, surely myThread in classA
deleted.auto_ptr
also cannot help.If i dont put this line,
my code is perfectly run,but of course
memory leaked.
}
//----------------------------------------------------------------


****LOT OF FUNCTION HERE****


My problem is my object of thread inside classA and object of classA
inside function myGUIFunctionNamed_Execute().I want
myGUIFunctionNamed_Execute()
return immediately after i called it,but i dont no how to delete
object(objectA)

If the object is automatic, rather than dynamic, you won't have this
problem.

You still have an issue with the lifetime of the object and the thread.
It generally isn't a good idea to delete an object that contains a
thread, assuming the thread uses the object's data, while the thread is
running.

--
Ian Collins.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.