본문 바로가기
프로그래밍 놀이터/안드로이드, Java

android largeheap

by 돼지왕 왕돼지 2015. 6. 6.
반응형

-
largeHeap 은 HoneyComb ( 3.0, SDK 11 ) 부터 등장.



-
reference doc.

http://developer.android.com/guide/topics/manifest/application-element.html#largeHeap


android:largeHeap


Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application. It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use this option consistently or they will have unpredictable results.
Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.


To query the available memory size at runtime, use the methods getMemoryClass() or getLargeMemoryClass().



-
주의사항 :
무조건적으로 사용하는 게 아니라, 메모리 최적화를 하고도 어쩔 수 없을 경우에 사용해야 한다. ( Leak 이 없어도 메모리를 많이 사용할 경우 )
다시 말하면 내 앱이 얼마나 많은 메모리를 사용하는지 파악이 된 후에 사용해야 한다.






-
단점 :
largeHeap 을 적용한 앱이 있을 경우 다른 앱들이 죽을 가능성은 조금 더 늘어난다.
GC 타임이 더 오래 걸릴 수 있다.
Task Switching 하거나 Common Operation 이 늦어질 수 있다.

참조 : https://developer.android.com/training/articles/memory.html



-
Ginger 미만의 버전에서는 VMRuntime class 를 사용해서 조정할 수 있다.
VMRuntime.getRuntime().setMinimumHeapSize( BIGGER_SIZE );

=> Android 2.3 부터 VMRuntime 은 공식적으로 사라진 class. 그래서 Ginger 에서는 현재까지 방법이 없다.



-
largeHeap 속성을 통해 얼마나 heap 이 늘어날지는 보장되지는 않는다.



-
ActivityManager.getLargeMemoryClass() or ActivityManager.getMemoryClass() 을 통해서 얼마나 증가될 수 있는지 알 수 있다.



-
ActivityManager.getLargeMemoryClass() reference doc.

http://developer.android.com/reference/android/app/ActivityManager.html#getLargeMemoryClass()

public int getLargeMemoryClass ()

Added in API level 11

Return the approximate per-application memory class of the current device when an application is running with a large heap. This is the space available for memory-intensive applications; most applications should not need this amount of memory, and should instead stay with the getMemoryClass() limit. The returned value is in megabytes. This may be the same size as getMemoryClass() on memory constrained devices, or it may be significantly larger on devices with a large amount of available RAM.


The is the size of the application's Dalvik heap if it has specified android:largeHeap="true" in its manifest.





-
AcvitiyManager.getMemoryClass() reference doc.

http://developer.android.com/reference/android/app/ActivityManager.html#getMemoryClass()

public int getMemoryClass ()

Added in API level 5

Return the approximate per-application memory class of the current device. This gives you an idea of how hard a memory limit you should impose on your application to let the overall system work best. The returned value is in megabytes; the baseline Android memory class is 16 (which happens to be the Java heap limit of those devices); some device with more memory may return 24 or even higher numbers.



-
<삼성 갤럭시 S5>

model = SM-G900S
getMemoryClass = 128 MB
maxMemory = 512 MB
getLargeMemoryClass = 512 MB



-
<펜택 베가 시크릿 업>

model = IM-A900S
getMemoryClass = 192 MB
maxMemory = 512 MB
getLargeMemoryClass = 512 MB






-
<LG G3>

model = LG-F400S
getMemoryClass = 256 MB
maxMemory = 512 MB
getLargeMemoryClass = 512 MB



-
<소니 에릭슨 아크>

model = LT15i
getMemoryClass = 32 MB
maxMemory = 32 MB



-
<LG G3 Beat>

model = LG-F470S
getMemoryClass = 96 MB
maxMemory = 256 MB
getLargeMemoryClass = 256 MB






반응형

댓글