iOS Question Memory management

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

Does anyone know how IOS frees up a memory and what is correct tactics ?

Imagine, that a page holds 100 imageviews. Pictures are static and have a fixed size.
So it's enough to read SVG and to export to imageview once.

In some moment the app switches to another page. And what to do with Imageviews on first page ?
To remove ? But in this case the app will need a time to recreate imageviews, when user switches to initial page again.

Probably, IOS uses virtual memory (like in Windows). Maybe not. Any ideas ?
 

Semen Matusovskiy

Well-Known Member
Licensed User
No. But I began to convert only.

In B4A I removed everything, what it was possible (to avoid memory leaks).

In B4I there is a wish to keep in global variables and do not destroy views (most of layouts are static).
If this is a wrong tactics, I don't want to find this on final stage :)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you can always use a static amount of imageviews and just change its content (bitmap) when a page change is requested and hide what's not needed.
 
Upvote 0

CaptKronos

Active Member
Licensed User
I have a similar concern/confusion to Semen. Coming from B4A where each activity is released once it is no longer being viewed, it seems strange to have all the iOS pages seemingly in memory all the time. However, I have never had any memory issues, so perhaps iOS is just very clever at swapping memory in and out?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I found old article https://developer.apple.com/library...tual/ManagingMemory/Articles/AboutMemory.html
It looks that there are serious restrictions for IOS

In iOS, the kernel does not write pages out to a backing store. When the amount of free memory dips below the computed threshold, the kernel flushes pages that are inactive and unmodified and may also ask the running application to free up memory directly.

I can agree that there is no reason to remove regular views (such as Label, TextView etc). They should not take a lot of memory anyway. Meanwhile iPhones have 1-3 GB of RAM.

But about graphic I am not so sure. If to take standard density (3 pixels per unit) even small picture 50 * 100 requires (50 * 3) * (100 * 3) * 4 = 176KB. So, I decided to reset imageview (according sorex's recomendation).
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
ViewController classes in apps written in Xcode have a didReceiveMemoryWarning function by default:

B4X:
    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }

You can use this function to take appropriate action if there is a memory issue. I'm not sure if it is implemented in B4i.

- Colin.
 
Upvote 0
Top