Code Module missing "Sub Globals"

Widget

Well-Known Member
Licensed User
Longtime User
I decided to move my animation code to a separate code module and I'm surprised to learn a code module does not have a Globals sub. I wanted this sub to contain variables that are global to this code module and not accessible from other modules. But it appears I can't do that. :confused:

Here is the problem. This code module needs to have a few Maps and Lists that contain Views, and of course I can't use Sub Process_Globals to store Views. So I thought I could use local global storage in the code module. The Views are passed from an Activity to the code module subroutine and are added to the Map/List. But it doesn't look like this is possible since there is no local global storage.

How do I store Lists/Maps in a code module? Any suggestions?

TIA
Widget
 

JesseW

Active Member
Licensed User
Longtime User
I need the same functionality as well, including the ability to define events in the code module. But alas, I must pass activity, sender and any other info to the code module calls... :(
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Code modules, unlike Activity modules do not have a lifetime and are always present so cannot store UI related items as that would constitute a memory leak of stuff the garbage collector could not reclaim.

You could keep the Lists and Maps in the Activity, where the Views are only valid anyway, and pass them as parameters to the Subs in the Code module. As parameters are effectively local variables they will not retain the List or Map references once they return and hence do not keep a reference to anything containing a UI object and so cannot cause a memory leak.
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
Code modules, unlike Activity modules do not have a lifetime and are always present so cannot store UI related items as that would constitute a memory leak of stuff the garbage collector could not reclaim.

You could keep the Lists and Maps in the Activity, where the Views are only valid anyway, and pass them as parameters to the Subs in the Code module. As parameters are effectively local variables they will not retain the List or Map references once they return and hence do not keep a reference to anything containing a UI object and so cannot cause a memory leak.

Agraham,
I took your advice and passed the Maps as parameters to the code module. With a little tweaking it worked well. :sign0060:

This actually makes more sense storing the maps (state) in the Activity and using parameters because the stateless Code Module can now animate multiple Activity windows.

Widget
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
...I believe that Public / Private scope identifiers will be added in the next version.

Sweet!!! Will you also consider Static (ie. persistent local) sub variables?

Sent from my DROIDX using Tapatalk
 
Upvote 0
Top