iOS Question Freeing up bitmap memory

JackKirk

Well-Known Member
Licensed User
Longtime User
Not sure if this is a question or comment - but would like some feedback.

I have just successfully (I think) got running an "infinite" scrolling images application that does the "make new images in scroll direction, delete old images in trailing direction" trick.

To delete the old images I found 2 forum hits:

1. https://www.b4x.com/android/forum/threads/how-to-unload-an-image-to-free-resources.55938/post-352064
by Erel which suggests:
B4X:
ImageView.Bitmap = Null
This does not work - I get:
Error occurred on line: 3326 (Show_list)
Object was not initialized (UIImage)
Stack Trace: (
CoreFoundation 4D6DD6DD-22E4-3858-9A0C-3CB77C2F13D6 + 1159852
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation 4D6DD6DD-22E4-3858-9A0C-3CB77C2F13D6 + 117712
Customer -[B4IObjectWrapper object] + 136
Customer -[B4IImageViewWrapper setBitmap:] + 72
Customer -[ResumableSub_show_list_Event_UI_dialog_XD_Event_Scroll_ScrollChanged resume::] + 10480
Customer -[b4i_show_list _event_ui_dialog_xd_event_scroll_scrollchanged:] + 496
CoreFoundation 4D6DD6DD-22E4-3858-9A0C-3CB77C2F13D6 + 1178192
CoreFoundation 4D6DD6DD-22E4-3858-9A0C-3CB77C2F13D6 + 5968
Customer +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
Customer -[B4IShell runGoodChain::] + 348
Customer -[B4IShell raiseEventImpl:method:args::] + 2408
Customer -[B4IShellBI raiseEvent:event:params:] + 1580
Customer __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib 3BBE17AC-597B-3B79-91AC-21A5523E7BD7 + 393904
libdispatch.dylib 3BBE17AC-597B-3B79-91AC-21A5523E7BD7 + 397976
libdispatch.dylib 3BBE17AC-597B-3B79-91AC-21A5523E7BD7 + 64736
CoreFoundation 4D6DD6DD-22E4-3858-9A0C-3CB77C2F13D6 + 631520
CoreFoundation 4D6DD6DD-22E4-3858-9A0C-3CB77C2F13D6 + 608064
CoreFoundation CFRunLoopRunSpecific + 572
GraphicsServices GSEventRunModal + 160
UIKitCore 186F3A78-108A-3057-A67E-800A88EBFF00 + 11731176
UIKitCore UIApplicationMain + 164
Customer main + 128
libdyld.dylib 5FFFB964-39D6-3CCF-BD34-C6CA4A148D1A + 4416
)
-----------------------------------------
2. https://www.b4x.com/android/forum/threads/reset-imageview-bitmap-bitmap-null-fails.69886/post-657831
by Semen Matusovskiy which suggests:
B4X:
Dim no As NativeObject
imageView1.Bitmap = no.Initialize ("UIImage").RunMethod ("new", Null)
Which seems to work - but not sure how to test.
-----------------------------------------
Am I doing something wrong that stops Erel's solution (which seems much more elegant) from working?

Is there a way to test if solution 2 is actually freeing memory?

Thanks....
 
Last edited:

JackKirk

Well-Known Member
Licensed User
Longtime User
There is more elegant way. Declare, for example, Dim DummyBitmap As Bitmap and use it in MyBitmap = DummyBitmap only.
What happens if the bitmap to be dummied is in an imageview - would memory be cleared?
 
Upvote 0
Top