Remove objects inside a module, working with composer!

Hi there,

so I have a mod which creates some display objects and text objects.
It’s called mod_textbox.lua.

When I am working with the composer I have to insert ALL objects into the “sceneGroup”.
So I understood it so that all this objects that are inside the “sceneGroup” will be automatically deleted when the scene is in the phase “destroy” when I am changing the scene.

But how about the objects in the module ?
The mod of course doesn’t have the composer with the sceneGroup.

So I tried it like this:

I insert all the objects inside the mod into a new group in the mod.

Then I insert this mod group (lets call it “textGroup”), inside the “sceneGroup” in the scene.lua which has required the mod_textbox on the top.
local textBox = require( “mod_textbox” )
sceneGroup:insert(textBox.textGroup)

This way I thought the objects will be destroyed.
But it isn’t so.

For example, when the mod has created a text object and I see some text and I change the screen, the text object is still there.

I also tried to remove the mod from package.loaded when changing the scene, but it doesn’t work too.

So how can I remove objects that are created inside a mod when I am changing the scene ?

Thanks in advance and best regards!
Dima

Anything which is still referenced by a variable in the module will remain in memory, even after the scene is removed. You need to unload a module if you want it to be completely removed, but that does not stop other modules having a reference to any variables (if you passed them out.) The composer documentation does not state the removing a scene removes it’s module from memory, but I believe that scene modules do, in fact, stay in memory.

To completely remove a scene and it’s associated variables you simply need to set every variable to nil in the destroy event. This is what I do and it works very effectively.

Anything which is still referenced by a variable in the module will remain in memory, even after the scene is removed. You need to unload a module if you want it to be completely removed, but that does not stop other modules having a reference to any variables (if you passed them out.) The composer documentation does not state the removing a scene removes it’s module from memory, but I believe that scene modules do, in fact, stay in memory.

To completely remove a scene and it’s associated variables you simply need to set every variable to nil in the destroy event. This is what I do and it works very effectively.