Scope statement

Bill Baxter dnewsgroup at billbaxter.com
Tue Feb 5 13:43:40 PST 2008


Lars V wrote:
> Hi, 
> 
> I have a question: 
> 
> void foo() 
> { 
>   Obj o = new Obj(); 
> }
> 
> In this code, the destructor of the object will be called ALWAYS at the end of the function? 
> 
> In D, the objects are not destroyed when they go out of their scopes??? Is necessary to use the "scope" statement? 
> 
> I really don't understand the necessity of the scope statement... could anybody explain it?

Yes you need to use scope if you want deterministic destruction.

Allocation and deallocation are expensive, and one of the nice things 
about a garbage collection system is that it lets you do clean-up more 
lazily.  That way you can handle a bunch of de-allocations at once. 
Think of it as waiting a week to vacuum up the room instead of pulling 
out the vacuum cleaner every time a piece of dust hits the floor.

--bb


More information about the Digitalmars-d-learn mailing list