www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is heap memory released after the termination of a thread?

reply "Vitali" <notavailable mail.com> writes:
Hello,
in [1] is said that data defined in modules, if it's not shared, 
is copied for each thread. This means that new memory for this 
data is allocated every time when a new thread is started and 
when the thread terminates it is released [2].

But how about the memory created by this thread on the heap? Is 
it released, too, especialy when the garbage collector is turned 
off?

Thank you.

References
[1] 
http://www.informit.com/articles/article.aspx?p=1609144&seqNum=3
[2] http://dlang.org/module.html
Jun 13 2013
parent "Peter Alexander" <peter.alexander.au gmail.com> writes:
On Thursday, 13 June 2013 at 12:50:49 UTC, Vitali wrote:
 Hello,
 in [1] is said that data defined in modules, if it's not 
 shared, is copied for each thread. This means that new memory 
 for this data is allocated every time when a new thread is 
 started and when the thread terminates it is released [2].

 But how about the memory created by this thread on the heap? Is 
 it released, too, especialy when the garbage collector is 
 turned off?
No, it will be released at some undetermined time later by the garbage collector, assuming nothing else references it. Remember that heap references can be sent across threads using std.concurrency.send (if it is safe to do so).
Jun 13 2013