Re: [android-developers] Total Available memory for Memory Management logic.

2012-04-26 Thread Daniel Drozdzewski
The thing is that Android OS will allocate the memory according to the
needs of a process (up to maximum memory allowed).

So, if were able to establish the amount of free memory that your app
has available, the OS might increase this allowance as soon as you
allocate next bitmap, therefore the whole method makes little sense.

Instead build a HashMap that uses soft references to build a primitive
cache with random eviction policy. The bitmaps will get removed as the
process is running low on memory. There are few good articles about
the usage of soft and weak references to implement primitive caches in
Java. This gives you a solution that will adapt to whatever memory
allowance is there (different per OS version) with all the memory
management duties shifted to the platform.

Here is one such article:
http://www.javaspecialists.eu/archive/Issue015.html


Daniel





On 25 April 2012 16:57, Anieeh animesh.andr...@gmail.com wrote:
 Hi all
    I am having problem with releasing memory problem, i have a
 Hashmap in which i am adding Bitmap object, and the no. of bitmaps are
 quite large. for this reason i am getting OutOfMemoryError. So for
 this i have decided to release Bitmap whic is least used from
 Collection, on memory crunch or system getting low heap memory.
  For getting current memory available i used
 ActivityManager.MemoryInfo.availMem but it gives total RAM size
 memory, not Available Heap memory. And i found that this memory is not
 getting updated on releasing  Bitmap from collection.

 Then i have used these three method
 Debug.getNativeHeapAllocatedSize()
 Debug.getNativeHeapFreeSize()
 Debug.getNativeHeapSize()

 but found the NativeHeapSize goes on increasing upto some certain say
 16MB changing after that an outOfMemoryError occur. In this also i
 found that the NativeHeapAllocatedSize and getNativeHeapSize not
 decreasing on releasing  Bitmap from collection.

 So please help me for solving the problem if anyone facing the same
 problem and fixed earlier it.

 My problem is i want to calculate Max Available application memory
 allocated and currently available memory, for such that if
 currently available memory goes beyond the Threshold memory i will
 release some Bitmap from the collection and GC will reclaim the memory
 and free it without generating error.

 Thanks in advance
 Anieeh

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en



-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Total Available memory for Memory Management logic.

2012-04-25 Thread Anieeh
Hi all
I am having problem with releasing memory problem, i have a
Hashmap in which i am adding Bitmap object, and the no. of bitmaps are
quite large. for this reason i am getting OutOfMemoryError. So for
this i have decided to release Bitmap whic is least used from
Collection, on memory crunch or system getting low heap memory.
  For getting current memory available i used
ActivityManager.MemoryInfo.availMem but it gives total RAM size
memory, not Available Heap memory. And i found that this memory is not
getting updated on releasing  Bitmap from collection.

Then i have used these three method
Debug.getNativeHeapAllocatedSize()
Debug.getNativeHeapFreeSize()
Debug.getNativeHeapSize()

but found the NativeHeapSize goes on increasing upto some certain say
16MB changing after that an outOfMemoryError occur. In this also i
found that the NativeHeapAllocatedSize and getNativeHeapSize not
decreasing on releasing  Bitmap from collection.

So please help me for solving the problem if anyone facing the same
problem and fixed earlier it.

My problem is i want to calculate Max Available application memory
allocated and currently available memory, for such that if
currently available memory goes beyond the Threshold memory i will
release some Bitmap from the collection and GC will reclaim the memory
and free it without generating error.

Thanks in advance
Anieeh

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Total Available memory for Memory Management logic.

2012-04-25 Thread Latimerius
I asked a similar question recently:

http://groups.google.com/group/android-developers/browse_thread/thread/5c26876b19de1a4d/d843121085218de7?lnk=gstq=bitmap.recycle#d843121085218de7

Check it out, Romain gave some good explanations there.

If you'd just like to free some memory on out-of-memory condition you
shouldn't need exact numbers (those are hard to get as explained in
the linked topic).  Why don't you just catch OutOfMemoryError and
handle it by freeing your least recently used bitmaps, then perhaps
restart the operation that caused the fault?  Do you need an early
warning (even before you actually run out of heap) for some reason?

On Wed, Apr 25, 2012 at 5:57 PM, Anieeh animesh.andr...@gmail.com wrote:
 Hi all
    I am having problem with releasing memory problem, i have a
 Hashmap in which i am adding Bitmap object, and the no. of bitmaps are
 quite large. for this reason i am getting OutOfMemoryError. So for
 this i have decided to release Bitmap whic is least used from
 Collection, on memory crunch or system getting low heap memory.
  For getting current memory available i used
 ActivityManager.MemoryInfo.availMem but it gives total RAM size
 memory, not Available Heap memory. And i found that this memory is not
 getting updated on releasing  Bitmap from collection.

 Then i have used these three method
 Debug.getNativeHeapAllocatedSize()
 Debug.getNativeHeapFreeSize()
 Debug.getNativeHeapSize()

 but found the NativeHeapSize goes on increasing upto some certain say
 16MB changing after that an outOfMemoryError occur. In this also i
 found that the NativeHeapAllocatedSize and getNativeHeapSize not
 decreasing on releasing  Bitmap from collection.

 So please help me for solving the problem if anyone facing the same
 problem and fixed earlier it.

 My problem is i want to calculate Max Available application memory
 allocated and currently available memory, for such that if
 currently available memory goes beyond the Threshold memory i will
 release some Bitmap from the collection and GC will reclaim the memory
 and free it without generating error.

 Thanks in advance
 Anieeh

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en