android-Java- converting a WeakReference<Bitmap> to a normal Bitmap
Ive been working on an app for a while that uses lots of Bitmaps and Ive gotten it to the point where its working really well on most devices that Ive tested it on except for a newer droid bionic that runs 2.3.4
I get an out of memory error and I can see the heap growing in the logcat too. So far Ive tried re-sizing the bitmaps with different techniques which works great for every other device except the new droid bionic which is weird being that you would think a newer phone would handle vm better.
Ive looked at some other threads on here that talk about using various methods but the one Im interested in using involves using WeakReferenced to store images as. This is great but how can I convert the weakreference back to a normal bitmap to use on a canvas.
EDIT: heres a recent stack trace dumparoo :p
09-30 12:33:09.231 2867 2922 E AndroidRuntime: FATAL EXCEPTION: go
09-30 12:33:09.231 2867 2922 E AndroidRuntime: java.lang.OutOfMemoryError
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.io.AbstractSessionInputBuffer.init(AbstractSessionInputBuffer.java:79)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:93)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:363)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at graffit.data.ImageGrabber.imagegetter(ImageGrabber.java:164)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at graffit.data.ImageGrabber.traverseIDS(ImageGrabber.java:118)
09-30 12:33:09.231 2867 2922 E AndroidRuntime: at graffit.开发者_JS百科data.ImageGrabber$getMarkImageThread.run(ImageGrabber.java:238)
09-30 12:33:09.239 480 750 W ActivityManager: Force finishing activity graffit.main/.GraffView
09-30 12:33:09.669 480 873 I ActivityManager: Process graffit.main (pid 2867) has died.
09-30 12:33:09.677 480 590 I WindowManager: WINDOW DIED Window{407c4100 graffit.main/graffit.main.GraffView paused=true}
09-30 12:33:09.677 480 590 I WindowManager: WINDOW DIED Window{408044e0 Toast paused=false}
09-30 12:33:09.684 480 759 I WindowManager: Setting rotation to 0, animFlags=1
Are you making http calls in your code using the Apache DefaultHttpClient?
I've recently discovered a problem specific to the Droid Bionic which causes it to use a lot more VM memory than other Android devices while downloading files using the HttpClient. This may be the true cause of your memory leaks if your are not experiencing an OutOfMemoryError on other devices.
Do you have any stack traces that indicate an OutOfMemoryError during a http call?
I believe the work-around code starting at line 64 in the following source maybe missing on the Droid Bionic build:
http://codesearch.google.com/codesearch#CskViEIa27Y/src/org/apache/http/impl/io/SocketInputBuffer.java&q=package:android.git.kernel.org%20file:org/apache/http/impl/io/SocketInputBuffer.java&l=1
You can fix this by using HttpConnectionParams.setSocketBufferSize(params, 8192) when you create your http client.
WeakReference.get()
精彩评论