Hi,

Is the work done on the background task properly protected using locks? It
might be that your code is "forgetting" about some images due to race
conditions.

You might also want to try the latest beta, there are a number of API you
can't call in background threads because they're not thread-safe, and the
beta will thrown an exception if this happens.

Rolf

On Tue, Apr 24, 2012 at 8:55 PM, WP7_MonoTouch <[email protected]>wrote:

> I need to read a lot of png images and show them like a video player. I
> developed my application on Windows Phone 7 using a background task that
> loads an image when it detects that the main thread needs a new file to
> show.
>
> void LoadTextureInBackground()
>    {
>        if (currentMovie == null) return;
>
>        DateTime timeOnstart = DateTime.Now;
>
>        // Mantenemos 2 texturas en memoria para no cargar sobre el mismo
> objeto texture.
>        string fileName = currentMovie.GetFileName();
>
>        if (lastFileName == fileName) return;
>
>        textureLoaded[currentTexture] =
> Texture2D.FromStream(Device.GraphicsDevice, fileName);
>
>        texture = textureLoaded[currentTexture];
>
>        currentTexture = 1 - currentTexture;
>
>        lastFileName = fileName;
>
>        GC.Collect();
>        System.Threading.Thread.Sleep(50);
>    }
>
> (Texture2D.FromStream it's only a wrapper for UIImage.FromFile)
>
>
>    /// <summary>
>    /// This is called when the game should draw itself.
>    /// </summary>
>    /// Provides a snapshot of timing values.
>    public void Draw(TimeSpan totalTime,TimeSpan elapsedTime)
>    {
>        if(currentMovie==null) return;
>
>       // Mantenemos 2 texturas en memoria para no cargar sobre el mismo
> objeto texture.
>
>        if (texture == null) return;
>
>        int newWidth = (int)(texture.Width*RenderSize);
>        int newHeight = (int)(texture.Height*RenderSize);
>
>        Texture2D drawTexture = texture;
>
>        // Al cargar usando Texture2D.FromStream, la textura NO lleva
> elAlpha premultiplicado
>
>        //Device.SpriteBatch.Draw(drawTexture, destination, Color.White);
>        if(CultTravel.AppDelegate.ImagePng.Image!=drawTexture.Texture)
>        {
>            AppDelegate.ImagePng.Image=drawTexture.Texture;
>            AppDelegate.ImagePng.Frame=new
>
> System.Drawing.RectangleF(0,480-newHeight,ImagePng.Image.CGImage.Width,newHeight);
>
>        // Si la textura que tengo cargada y lista para mostrar es diferente
> a la que mostraba, libero la antigua
>        if (lastTextureDraw!=null && lastTextureDraw != texture)
>        {
>            lastTextureDraw.Dispose();
>        }
>
>        lastTextureDraw = texture;
>
>    }
>
> Everything is ok in the emulator but in the iPad, after a minute or
> something like that, the debugger informs me about a 'memory pressure'.
>
> I solved this issue calling to the GC.Collect() method, but I MUST DISABLE
> THE BACKGROUND TASK ( and hence do all the loading stuff in the Draw
> method)
>
> I've tried to do the GC.Collect in the background task. It doesn't work.
>
> I've tried to do the GC.Collect in the background task & the main task. It
> doesn't work.
>
> So, there is something 'different' i should do for collect the memory and
> enable the background task again?
>
> Thanks!!
>
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/Memory-pressure-loading-a-bunch-of-PNG-images-in-MonoTouch-tp4584493p4584493.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to