Object arrays in D
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Apr 11 10:12:50 PDT 2012
On Wed, Apr 11, 2012 at 07:07:54PM +0200, Johannes Pfau wrote:
> Am Tue, 10 Apr 2012 20:28:28 +0200
> schrieb Marco Leise <Marco.Leise at gmx.de>:
>
> > Am Tue, 10 Apr 2012 07:35:31 -0400
> > schrieb "Steven Schveighoffer" <schveiguy at yahoo.com>:
> >
> > > Destructors are strictly for cleaning up resources that *AREN'T*
> > > allocated by the GC. For example anything created with C's
> > > malloc, or an open file descriptor, etc.
> >
> > This I think is a very good advice to beginners. Short and precise.
> > It is much more fun to use a new language when you can also free
> > your mind from some archaic concepts now and then :)
> >
>
> That's a dangerous advice though: You can create lots of file
> descriptors without allocating much memory. So in the worst case you
> run out of file-descriptors long before the GC calls your destructor.
Yeah, one should not rely on the GC to destroy objects at a given time,
since it can be arbitrarily distant in the future. For releasing
resources, what really should be used are scope statements:
auto myResource = acquireResource;
scope(exit) myResource.release();
T
--
Windows 95 was a joke, and Windows 98 was the punchline.
More information about the Digitalmars-d
mailing list