Extreme memory usage when `synchronized( this )` is used

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 11 10:01:55 PDT 2015


On 05/11/2015 09:50 AM, tcak wrote:

 > On Monday, 11 May 2015 at 15:38:55 UTC, Ali Çehreli wrote:
 >> On 05/11/2015 03:48 AM, tcak wrote:
 >>
 >> > I think `destroy`'s behaviour should be documented much
 >> better.
 >>
 >> Could others tell us the missing pieces please.
 >>
 >> Perhaps related to this discussion, the following document says "does
 >> not initiate a GC cycle or free any GC memory":
 >>
 >>   http://dlang.org/library/object/destroy.html
 >>
 >> Thank you,
 >> Ali
 >
 > Setting object's reference to null, and destroy are very different based
 > on my experience.

I see. There are the following differences that I know:

Setting the object to null should not have any immediate effect. It 
merely erases a single reference to the object. If there is no other 
reference to it, the object will be collected in the future, including 
running its destructor.

Regarding your original code, setting it to null should have no effect, 
because the test code had a single reference anyway.

destroy() executes the destructor of the object right away. So, just the 
memory that was used for the object remains but provided that the 
destructor is written correctly, the resources that the object owned 
should be returned.

 > Because if same things were happening at the end, that memory
 > increase shouldn't have been happening.

Yeah, luckily it is just a regression that should be fixed soon.

 > What I meant with documenting it better was this.

There is also the new behavior of running the destructors of a struct 
object even if were constructed by new. In the past, the destructors of 
dynamic struct objects would not be executed by the GC.

Ali



More information about the Digitalmars-d-learn mailing list