Issue 3691 in dart: Allow cleanup of an object through a destructor or dispose method

595 views
Skip to first unread message

da...@googlecode.com

unread,
Jun 15, 2012, 8:54:06 PM6/15/12
to bu...@dartlang.org
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 3691 by Don.J.Ol...@gmail.com: Allow cleanup of an object through
a destructor or dispose method
http://code.google.com/p/dart/issues/detail?id=3691

Dart should have a destructor or dispose method
<http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx>, for when an object
is marked to be collected.

To give a use case where this would be useful lets say you had a Texture
class which contains a WebGLTexture. When you're done using
the WebGLTexture it should be disposed of by calling deleteTexture
through a WebGLRenderingContext. So if you were sharing this Texture
between other objects it isn't entirely clear when its okay to call
deleteTexture. A destructor or dispose method would provide a clear place
to call deleteTexture safely.

Having a destructor or dispose method could also be of use for those trying
to embed Dart in a C/C++ program.


da...@googlecode.com

unread,
Jun 16, 2012, 5:01:52 PM6/16/12
to bu...@dartlang.org
Updates:
Status: Triaged
Labels: -Type-Defect Type-Enhancement Area-Library Library-Core

Comment #1 on issue 3691 by seth...@google.com: Allow cleanup of an object
through a destructor or dispose method
http://code.google.com/p/dart/issues/detail?id=3691

(No comment was entered for this change.)

da...@googlecode.com

unread,
Apr 8, 2013, 5:50:16 AM4/8/13
to bu...@dartlang.org

Comment #2 on issue 3691 by zefhe...@gmail.com: Allow cleanup of an object
through a destructor or dispose method
http://code.google.com/p/dart/issues/detail?id=3691

Another use case of this is when wrapping JavaScript objects as Dart
objects that have to retain a reference to the wrapped object. For instance:

class EditSession {
js.Proxy sessionProxy;

EditSession.proxy(js.Proxy session) {
sessionProxy = session;
}

// ...

void dispose() {
js.release(sessionProxy);
}
}

Right now you have to basically manually do garbage collection on
Javascript objects that need to have a longer life time.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

da...@googlecode.com

unread,
Aug 26, 2013, 1:55:47 AM8/26/13
to bu...@dartlang.org

Comment #3 on issue 3691 by l...@google.com: Allow cleanup of an object
through a destructor or dispose method
http://code.google.com/p/dart/issues/detail?id=3691

Preferably, I'd like to not make garbage collection visible.

Right now, the spec does not say anything about garbage collection. If an
object is no longer reachable, the spec doesn't say what should happen to
it. It is a valid implementation to keep it alive forever (it's just not
very memory efficient).
That makes garbage collection an implementation detail.

If we start making it visible when an object is no longer reachable, by
calling a dispose method, then we either get unpredictable behavior, or we
have to specify when this callback should happen, which will only put
restrictions on what the VM can do (and will likely be hard or impossible
in dart2js code for a long time, depending on which GC-related features
goes into ES6).

da...@googlecode.com

unread,
Jun 15, 2014, 3:21:05 PM6/15/14
to bu...@dartlang.org

Comment #4 on issue 3691 by giova...@atende.info: Allow cleanup of an
object through a destructor or dispose method
http://code.google.com/p/dart/issues/detail?id=3691

Another use case is when you create a class to represent a dom object. The
class old a reference to the Element in the page and when is disposed the
dom element should be removed.

da...@googlecode.com

unread,
Sep 7, 2014, 6:39:08 PM9/7/14
to bu...@dartlang.org

Comment #5 on issue 3691 by normandi...@gmail.com: Allow cleanup of an
object through a destructor or dispose method
https://code.google.com/p/dart/issues/detail?id=3691

Please implement it to make possible RAII, it's important for server-side.

da...@googlecode.com

unread,
Oct 23, 2014, 12:37:58 PM10/23/14
to bu...@dartlang.org

Comment #6 on issue 3691 by fmuad...@gmail.com: Allow cleanup of an object
through a destructor or dispose method
https://code.google.com/p/dart/issues/detail?id=3691

Garbage collection should not be visible. But you must be able to manually
destroy any object exacly like the Garbage collector would do. In this way
the Garbage collector will have one less object to worry about.
The ability to manually destroying object instantly is ESSENTIAL for many
algorithms and patterns. Not only for RAII (Resource Acquisition Is
Initialization) techniques for servers, but also for many game loops where
immediate destruction of objects is essential to keep the number of objects
in memory constant at any time and consequently always contained inside the
cache, for assuring decent performances.
Note that what is required is not to "flag" an object to be "ready" to be
collected, but to collect it straight and directly, removing it immediately
from memory without calling the garbage collector at all, but just updating
its object graph to remove the reference just before the destruction.

da...@googlecode.com

unread,
Oct 23, 2014, 12:47:11 PM10/23/14
to bu...@dartlang.org

Comment #7 on issue 3691 by fmuad...@gmail.com: Allow cleanup of an object
through a destructor or dispose method
https://code.google.com/p/dart/issues/detail?id=3691

Garbage collection should not be visible. But you must be able to manually
destroy any object exacly like the Garbage collector would do. In this way
the Garbage collector will have one less object to worry about.
The ability to manually destroying object instantly is ESSENTIAL for many
algorithms and patterns. Not only for RAII (Resource Acquisition Is
Initialization) techniques for servers, but also for many game loops where
immediate destruction of objects is essential to keep the number of objects
in memory constant at any time and consequently always contained inside the
cache, for assuring decent performances.
Note that what is required is not to "flag" an object to be "ready" to be
collected, but to collect it straight and directly, removing it immediately
from memory without calling the garbage collector at all, but just updating
its object graph to remove the reference just before the destruction.
Of course destroying an object would be unsafe without an ARC (Automatic
Reference Counting) system, so Dart should also implement it. In this way
the user would be able to check for references before destroying the
object, like this:

if(sessionProxy.referenceCount == 0)
{
js.destroy(sessionProxy);
Reply all
Reply to author
Forward
0 new messages