Android Question How to create an app to occupy a large part of the device memory

LucaMs

Expert
Licensed User
Longtime User
Given that I'm waiting the O.S. kills my app which is in background, for a test, I would develop an app which can occupy a large part (or all) of the device memory :).

Any idea?

A loop that adds ImageViews to an activity (in the Activity_Create) containing big images?
 

sorex

Expert
Licensed User
Longtime User
it can be done easier.

try something like this

B4X:
For x=0 To 9999
    Dim y(65535) As Byte
Next

or put the dim in a timer
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Given that I'm waiting the O.S. kills my app which is in background, for a test, I would develop an app which can occupy a large part (or all) of the device memory :).

Any idea?

A loop that adds ImageViews to an activity (in the Activity_Create) containing big images?
I fear that this kind of app will fill only the memory dedicated to its process. I need to know if I can reserve a lot of memory to an application
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I mean: there is a limit of memory for each app; then I suppose that, if an app occupy this quantity of memory, the app crashes but my other app in background is safe (and I want the system kills it :D) (sorry for my english, sigh).

I'm searching for heap space
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I guess it depends if you stick to java or use these C based object files. they seems to be able to deal with more memory.

It might kill your background app to free resources for the forground one.
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
To have reallistic process killing, Create more than one app to run in the background and load a large bitmap in memory.

Also in the apps, add this line to the manifest:

B4X:
SetApplicationAttribute(android:largeHeap, "true")
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
To have reallistic process killing, Create more than one app to run in the background and load a large bitmap in memory.

Also in the apps, add this line to the manifest:

B4X:
SetApplicationAttribute(android:largeHeap, "true")
The largeheap parameter won't consume all the memory (on some devices, it's far from being the case) and you're not sure that you will kill the instance of your test app this way (Android may decide to kill the other instances of your apps created to fill the memory instead). And creating many apps to fill the memory requires to launch them, one by one.
The only convenient and efficient method is in post #12. It simulates what happens with a big game.
 
Upvote 0
Top