Scope statement
Lars V
nospamplease at nospam.com
Tue Feb 5 17:00:38 PST 2008
Michel Fortin Wrote:
> On 2008-02-05 18:26:50 -0500, Lars V <nospamplease at nospam.com> said:
>
> > But, when the function ends the object should be collected by the GC
> > (there are no more references to it) and the GC will call the
> > destructor, no? I don't understand it.
>
> The garbage collector will generally destruct and deallocate the object
> when you ask for more memory, if there are no more reference to it (it
> doesn't scan memory for pointers each time a function returns). This
> could happen the next time you call new, or in a few more calls to new.
>
> Basically, when to dispose of the object is left to the discretion of
> the garbage collector which may optimize things in various ways you
> shouldn't have to care much about. If you need deterministic
> destruction for your object, either use scope or call the destructor
> yourself (using delete).
>
> --
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
>
OK, thanks for all the replies.
Only one more question;
the deterministic destruction of the object -using scope or delete- will force the GC to collect it? or it'll only call the destructor?
More information about the Digitalmars-d-learn
mailing list