How can I kill objects?
I will explain.
I am building an application based on one activity whose center is a panel to which I load the various screens.
For each screen I create the object that runs it.
When I load a screen, I remove the current screen
but its object remains alive.
So after several times the app crashes from the next exception.
I know I can create each object once and then display it over and over
but I have about 30 screens that most will rarely be used so I prefer not to waste memory.
What's the way to do that?
Attached is an example project
I will explain.
I am building an application based on one activity whose center is a panel to which I load the various screens.
For each screen I create the object that runs it.
When I load a screen, I remove the current screen
B4X:
viewPnl.RemoveAllViews
but its object remains alive.
So after several times the app crashes from the next exception.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
java.lang.OutOfMemoryError: Failed to allocate a 235140 byte allocation with 121104 free bytes and 118KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
at android.graphics.Bitmap.createBitmap(Bitmap.java:856)
at android.graphics.Bitmap.createBitmap(Bitmap.java:823)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:81)
at anywheresoftware.b4a.objects.B4XCanvas.Initialize(B4XCanvas.java:37)
at b4a.example.homescreeno._drawdiamond2(homescreeno.java:149)
at b4a.example.homescreeno._screenclock_tick(homescreeno.java:446)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
java.lang.OutOfMemoryError: Failed to allocate a 235140 byte allocation with 121104 free bytes and 118KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
at android.graphics.Bitmap.createBitmap(Bitmap.java:856)
at android.graphics.Bitmap.createBitmap(Bitmap.java:823)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:81)
at anywheresoftware.b4a.objects.B4XCanvas.Initialize(B4XCanvas.java:37)
at b4a.example.homescreeno._drawdiamond2(homescreeno.java:149)
at b4a.example.homescreeno._screenclock_tick(homescreeno.java:446)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
I know I can create each object once and then display it over and over
but I have about 30 screens that most will rarely be used so I prefer not to waste memory.
What's the way to do that?
Attached is an example project