Hi guys,
I really need your help and advice with a particular on-going issue I am experiencing to do with system memory leak and the use of modular functions.
Basically, I had a lot of coding for a level, but at the same time I wanted to use the same coding for all the levels, and so it made sense to modularise my functions (templating them, effectively) . And so I did the usual thing of putting the functions into external modules and then calling them in to my main script for the level. For example, this is what the script inside my external module might look like
local m = {} local functionInsideModule = function (obj) local functionobject = display.newImage("objectImage.png") -- here I would change some values etc obj.relevantValue = 2 return functionobject end m.functionInsideModule = functionInsideModule
And I would then bring this into my script for Level4 like so:
local externalMod = require("external-mod") --every time I want to use that created object I know use it like this transition.to(externalMod.functionInsideModule.functionObject, {x= 100, time= 100})
However, the problem I am having, I think (because I don’t know for sure what the exact problem is so I need your help), is that with all these variables being shared between the main level scritpt and the external module, my system memory usage is going up.
However, I cannot really think of another way to do it, as it would be very helpful for me to modularise these functions, as it really helps organisation etc. if I can compartmentalise the functions, and share them between levels.
Does anyone have any advice on what can be done here? How do you modularise coding and functions, but at the same time share the objects and variables that are created within those functions between your module and your main script - without raising the system memory usage too much?
Any help you could give guys would be REAAALLLY appreciated! Thanks in advance!