Clear an Activity module from memory?

cyiwin

Active Member
Licensed User
Longtime User
Hello, in my program I'm using the Type command :

B4X:
Type Laser(LaserBitmap(41) As BitmapData,Target(41) As String, Xmoved(41,401), Ymoved(41,401) As Double, LaserAlive(41) As Boolean, LaserDamage(41), Xdistance(41), Ydistance(41), Chose(41), LaserFrames As Int)

The current Activity module runs fine, then when I call a new Activity module, I it does this:

LogCat connected to: f10aa745
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
(Main, 40) FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. (warning #1004)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (combat) Create, isFirst = true **
** Activity (combat) Resume **
** Activity (combat) Pause, UserClosed = true **
** Activity (map) Create, isFirst = true **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
Downsampling image due to lack of memory: 16
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
Downsampling image due to lack of memory: 16
map_activity_create (B4A line: 182)
Activity.LoadLayout("SpaceMap")


It never loads Activity "SpaceMap". If I lower the arrays from 41 to 12 and re-run the program, it will open Activity "SpaceMap" just fine. It seems the arrays are stuck in memory and won't release enough to open the next activity. I only need my app to remember a few variables, not all of the arrays and such.

I don't understand why it's trying to remember all the variables anyway since I put them in Sub Globals not Sub Process Globals. My question, is there a way to manually clear the memory? I've tried clearing the views, Activity.Finish, Activity.RemoveView, gv.RemoveView but it seems I need to clear the variables instead?

Is there a way to clear an Activity module from memory before Starting a new Activity module?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Are these different images (the ones you load in the first activity and the ones you load in the second one)?

Calling Activity.Finish will release the reference to this array. Assuming that there isn't any other reference then the images memory should be eventually released. However it might not happen immediately.
 
Upvote 0

cyiwin

Active Member
Licensed User
Longtime User
They are different images. I am having more luck by using

B4X:
Activity.RemoveAllViews
StartActivity("New_Module_Here")

It seems to free up memory for me.
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
Hi cyiwin,

Could you give an example snippet of code as to how you do that?

I'm having a similar problem.
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
It's ok, figured it out (was manipulating Activities from a service )
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…