Skip to content

object: Discard disposed GObject's and do not create wrappers for them

Marco Trevisan requested to merge 3v1n0/gjs:ignore-disposed-objects into master

This is from the main commit fixing the issue, there are other commits included here that are not strictly needed for the issue (such as the finalization handling) but are completing the change.


As per commit d37d6604 and commit c0003eb5 we may destroy an object wrapper earlier than we used to do, this has some memory benefits but we also need to make sure that we cleanup the object qdata so that it never points to the just free'd object wrapper.

By doing this, however, we may end up re-associating a GObject that is disposed but not yet finalized to another wrapper. This was allowed before but wasn't really correct either because in such case it will be just useless and won't be able to monitor it's disposition again.

So, now during disposition notify save a qdata (that won't be removed until finalization) on gobject marking it as disposed, then use this data to prevent an object to be re-associated again to a wrapper. When this happens we just set the underlying JS object as undefined (so that can be properly seen as non-null, but still behaving in a similar way). We don't warn though, because that will prevent safe null checking of a such object.

Added tests simulating this.

Fixes: #395 (closed), #399 (closed), #294 (closed)

Edited by Marco Trevisan

Merge request reports