Is disconnecting from signals always required?

Extension review guidelines state that:

Any signal connections made by an extension MUST be disconnected in disable():

I understand why it’s required when connecting to “external” objects, i.e. those created/owned by the shell. But does it also apply to GObjects created by the extension?

For example: I create a custom GObject subclass with a signal, create an instance of it and connect to the signal in enable(), then set the reference to null in disable(). Will the signal handler that I didn’t disconnect cause a memory leak? (My tests with System.dumpHeap()+heapgraph show that the object is successfully collected - unless I’m doing something wrong or misunderstanding)

Even extensions from gnome-shell-extensions don’t disconnect everything.

That’s correct, if a GObject is collected by the garbage collector, then all signal handlers will be disconnected when it’s disposed.

Extensions that clearly null out GObjects, that don’t have complex chains of references, will pass review. If it’s difficult to determine if/when a signal is disconnected or its object destroyed, the reviewer may ask for clarification or assume it was a dangling signal handler left by mistake.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.