Reputation: 433
How to allocate more then 192MB of memory on device, when running application from Android Studio level?
I've created simple app that performs matrix-vector multiplication in comparison purposes. I'm running app on my Nexus 5 via Android Studio, but it goes out of memory pretty fast. The maximum size of matrix that is possible to allocate is about [9000]x[9000] of short integer type. That gives about 162MB, so it shouldn't be too much since device has about 650MB free memory. However apps crashes with OOM at 192MB, what seems to be some kind of limit, since Android Studio memory monitor displays only chart of such height (as on below screenshot).
Unlimited memory (up to device limit level) would be perfect. Any chance to achieve that?
Upvotes: 0
Views: 1502
Reputation: 1006759
That gives about 162MB, so it shouldn't be too much since device has about 650MB free memory
Device memory is not your problem. Your problem is that Android apps that use Dalvik/ART — in other words, apps written using Java — have a heap limit. This limit could be as low as 16MB, though higher values are more common nowadays.
However apps crashes with OOM at 192MB
You have a fairly high-end device if your heap limit is 192MB; most devices will not have nearly as high of a heap limit.
Unlimited memory (up to device limit level) would be perfect. Any chance to achieve that?
Learn C/C++, then write your vector code using that. Native code can allocate up to the device limit.
Or, as Redshirt notes, you may be able to allocate more memory using android:largeHeap="true"
on your <application>
element in your manifest. There is no requirement for the device manufacturer to give your app more memory if you request it this way, but it might. However, this will not get anywhere near the device memory limit, in all likelihood.
Please note that users get very irritated with developers who misbehave, such as allocating far too much memory, harming the users' use of other apps.
Upvotes: 2
Reputation: 674
The memory limit is set by the device not Android Studio. The only way to get around this limit is to add android:largeHeap=true
in your manifest, but it's severely frowned upon unless the developer knows what they are doing.
Some devices have significantly less than 192MB available to apps, so you can't even rely on the 192MB.
Upvotes: 2