Hi Gabriel,
On 26.05.2020 14:41, Gabriel Ivăncescu wrote:
Signed-off-by: Gabriel Ivăncescugabrielopcode@gmail.com
We have to treat a ref count of 0 in a special manner when they are linked to the script control, because the modules must exist even when they have no external refs (as the script control can still use them).
However, as evidenced by the tests, they must*not* keep a ref to the script control in this case, as it would create a circular ref and make no sense, anyway.
The alternative solution to allocate separate data for modules would require copying the data to multiple places (one for Module Collection, and one for orphaned Modules) which is more complicated, in my opinion.
There must be a cleaner way. If you need too much special treatment for orphaned modules, it means that the design needs to be improved. One thing that is often useful for similar cases are weak reference: never reference control from module and make sure that control always invalidates the module->control pointer when it actually releases the object.
Thanks,
Jacek