Limiting the file size of an Android app

Can I limit the size of an Android app? (say in the manifest)

The point is the following: the client wants the application not to exceed, say, 20 MB. But the available memory in the device is say 50MB. The app has a Webview in one of the Acts that keeps growing and therefore increases the overall size of the app. So it's possible: when no webview is needed (already set to zero) and total memory size> 30MB. GC is called strong? Note. We are confident that other components and actions do not require more than, say, 5 MB of memory.

+3


source to share


1 answer


Can I limit the size of an Android app? (say in the manifest)

Not really. The app heap limit is determined by the device, not the app. The only thing an application can do is android:largeHeap

request a large heap; there is no way to request a smaller heap.

Also note that the allocations you make through the NDK do not count towards the heap limit. To do this, you are completely on your own.

The client wants the app to not exceed, say, 20 MB

Your customer can create their own device or ROM that can enforce this limitation, at least for distribution in Dalvik / ART VMs.

Or your client shouldn't be using Android, but rather something like embedded Linux, where they have a lot more control over memory usage.



But the available memory in the device is say 50MB.

The amount of available system memory on a device is not directly tied to the application heap limit.

If webview is not needed (already set to zero) and total memory size> 30MB. GC is called forcibly?

You can try to implement this yourself. In general it won't work, but you can implement it.

Once the VM allocates memory from the OS, it will only return that memory to the OS if that memory is no longer in use. Dalvik - a virtual machine used on Android 4.4 and below - does not compact the heap, and so even if you can collect some memory for garbage collection, it may not reduce the overall heap size.

Also note that some of the system RAM consumed WebView

includes the core WebKit / Blink libraries. As far as I understand, they are dynamically loaded when you first use them WebView

(so your first one WebView

might take a while to load). But these code segments are probably not freed until after the process is complete.

+6


source







All Articles