Any way to avoid garbage collection on these lines? Bitmap.createBitmap / new Canvas(bitmap)

by Mark Murphy » Tue, 14 Apr 2009 22:12:18 GMT


Sponsored Links
 > I'm happy to keep a static or member reference to the Bitmap object




To me, the key word there is "many".

If really do mean "many", then cache the Bitmap (or perhaps the Canvas) in
a data member or local variable or something until you are outside your
loop and no longer need it. If at that point you are not expecting to
re-enter that loop for some time, null out the data member and let garbage
collection reclaim the space. If you are likely to re-enter the loop soon
and will need the exact same Bitmap again, you may as well hold onto it.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. bagaimana cara HTC Hero biar connect wifi adho

sesuai dgn judul...
mohon bimbingannya ke suhu2....

-- 
"Indonesian Android Community [id-android]" 

2. ANR discussion

Hi all,

Be one of Android developers, you must be aware of  the
ANR(Application Not Responding) very well and understand how to avoid
it. There are many ways you can choose to do. I usually create a
thread and use a flag
to trigger it to handle time-consuming tasks. For example:

public class ActivityA extends Activity implements OnClickListener{
    private boolean isDestroyed = false;
    private FetchThread thread;

    public void onCreate(Bundle b){
        super.onCreate(b);
        .
        .
    }

    public void onDestroy(){
        super.onDestroy();
        isDestroyed = true;
    }

    public void onClick(View view){
        thread = new FetchThread();
        thread.setStartFlag(true);
        thread.start();
    }

    class FetchThread extends Thread{
        private boolean shouldStart = false;
        public void run(){
            while (!isDestroyed){
                if (shouldStart){
                    shouldStart = false;;
                    // do time-consuming task
                    // after task is finished, use handler to update
UI
                }
                try{
                    sleep(500);
               } catch (Exception ex){}

            }
        }

       public void setStartFlag(boolean b) {   shouldStart = b;}
    }
}

The above is the way I usually do and it's as the same as running one
background service. Does anyone be able to provide your solution? I
think my method is not very smart. :(

NightGospel

-- 

3. signal of gprs is zero

4. 绛斿: signal of gprs is zero

5. Does MediaPlayer support MP3+G or .kar file formats?

6. QuickDesk!

7. Help need for writing the asound.conf file Sigma 8654