Hi,
I am using a background thread for this normally. I moved the code to the UI
thread to see why it was giving problems. Because when I run this on a
background thread I get crashes after a few seconds.
The bitmap itself is 1kb in size, so it should download in no time on the
emulator.
The weirdest thing is that when I use
var stream = new Java.Net.URL("MyUrl").OpenStream();
BitmapFactory.DecodeStream(stream);
It works fine :S
I think there's something wrong with the combination of components here.
Van: [email protected]
[mailto:[email protected]] Namens Greg Shackles
Verzonden: Wednesday, August 17, 2011 11:47 PM
Aan: Discussions related to Mono for Android
Onderwerp: Re: [mono-android] GC troubles downloading a bitmap from a internet
resource
I can't speak to any GC problems, but I'm curious: is this a large bitmap that
takes awhile to download? The code you have there to download the file is
synchronous...are you running it on a background thread when you call it? If
you're doing a long-running synchronous operation on the UI thread, that would
certainly explain your app locking up.
On Wed, Aug 17, 2011 at 5:04 PM, Willem Meints
<[email protected]<mailto:[email protected]>> wrote:
Hi,
Anybody ever observed the following behavior when trying to download an image
from the internet?
The following code:
private Bitmap LoadThumbnail(Uri eventImageUri)
{
Bitmap result = null;
try
{
var request = HttpWebRequest.Create(eventImageUri);
var response = request.GetResponse();
if (response.ContentLength != 0)
{
Stream responseStream = response.GetResponseStream();
result = BitmapFactory.DecodeStream(responseStream);
responseStream.Close();
}
}
catch (Exception e)
{
DeviceContext.Current.Log.WriteError(e);
}
return result;
}
Causes the GC to start collecting chunks of 2K and the app to stop responding.
I'm not doing doing anything weird, so I can't really relate to the problem I'm
seeing :S
LOGCAT OUTPUT
======================
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/9015K, paused 54ms
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/9015K, paused 46ms
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/9015K, paused 53ms
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/9015K, paused 49ms
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/9015K, paused 54ms
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/9015K, paused 48ms
D/dalvikvm( 1244): GC_EXPLICIT freed 2K, 56% free 3226K/7175K, external
5598K/90....
Kind regards,
Willem Meints
_______________________________________________
Monodroid mailing list
[email protected]<mailto:[email protected]>
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid