Android Out of Memory error when postInvalidate
private void startGameTimeElapseThread(){
new Thread(new Runnable() {
Date d = new Date();
public void run() {
while (true){
try {
synchronized (this) {
this.wait(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
开发者_如何学Go postInvalidate();
}
}
}).start();
}
when i execute the above method it gives me the below error.
05-27 08:52:56.910: ERROR/AndroidRuntime(12715): FATAL EXCEPTION: main
05-27 08:52:56.910: ERROR/AndroidRuntime(12715): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
Does any one have any idea how to keep refreshing the screen every second without getting this error. ( in the canvas i draw a bitmap there. This says that bitmap causes this error )
There is an memory leak in your application. postInvalidate()
causes the the whole ViewGroup
to be redrawn. It's possible that a weak reference to your bitmap remains somewhere, or a weak reference to an Activity / View is present in the Heap which the GC can't free.
Since you have not posted much code, here is a link on how to trace the leaks in your application.
精彩评论