LiveCode do received memory warnings?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

LiveCode do received memory warnings?

Post by Mag » Mon Jul 28, 2014 11:46 am

I ask this in a simple way, do LiveCode receive memory warnings? I'm working on a project for iOS and I would be helpful to receive this message from the system when necessary.
From the Apple Developer site:
Observe Low-Memory Warnings
When the system dispatches a low-memory warning to your app, respond immediately. iOS notifies all running apps whenever the amount of free memory dips below a safe threshold. (It does not notify suspended apps.) If your app receives this warning, it must free up as much memory as possible. The best way to do this is to remove strong references to caches, image objects, and other data objects that can be recreated later.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: LiveCode do received memory warnings?

Post by Mark » Fri Aug 01, 2014 8:56 am

Hi,

No, I don't think LiveCode displays a message if such a warning is received from iOS. However, most LiveCode apps are of a type that has very little flexibility with regard to memory. The engine itself needs at least 4MB of real memory and when you add interface elements, you'll need a few MB extra. You will also need anything between 1 and 100 MB for displaying photos, depending on size and resolution. A 2 MB JPEG picture on disk may need 50MB when displayed on screen, for instance. If you include an MP3 in your project, you might need a few MB extra. The app as a whole may between 50 and 500 MB. There is little you can do about this, while the app is running.

The type of memory usage that one may purge if such a warning notice appears is often limited to a few declared (global and local) variables with text data. Sometimes, a variable may contain the text of an image or imageData, but most of the time it will contain an XML tree of a few kilobytes and user preferences of a few bytes. Let's say that you might free up 20 megabytes if your app would get a notice from iOS and only if you're keeping something like an image in a variable (which would be inefficient anyway).

The amount of purgeable memory compared to the amount of static memory used by your app is very small. Probably, it won't be enough to keep make your iPhone work normally again. Therefore, such notifications probably wouldn't help.

It is certainly possible that you're using too much memory. Once, I had a customer who loaded all his videos, images, sounds, 100+ substacks, etc. into memory at once. The file was over 1 GB and the computer's swap file would blow up. If you're worried that you are using too much memory, set the destroyStack and destroyWindow properties of stacks to false, use referenced image and player controls, set the alwaysBuffer of your controls to false, and use low(er) resolution pictures. Whenever possible, replace image objects with graphic objects.

LiveCode does have a hasMemory function, which checks the amount of available free memory. This function is of very limited use, as it checks the amount of memory available in the application heap (i.e. what is currently reserved for your app) and it may return false while the OS still can increase the app's heap by the amount requested by the function. The LC documentation warns that it is implemented partially in Mac OS, but the warning also applies to Windows 8 and probably all Windows versions.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply