locked
WritableBitmap and memory troubles RRS feed

  • Question

  • I have simple application, for explore medical DICOM images with dcm format and i use own dicom library for decode ImageBuffer's. I have Image control and WritableBitmap objects for demostration of images. But WritableBitmap doesn't contains methods for free resources and i have about 500 MB memory allocation in my process after demonstration of 15-20 images. Please help.
    Wednesday, May 30, 2007 3:53 AM

Answers

  • YES! I find mistake. I have DispatcherTimer on my UserControl with showImage. Timer should be stopped inside unloaded event! And it was great! It's work. But it's realy strange, becouse i'm releasing showImage.Source reference in unloaded event. Thanks!
    Wednesday, May 30, 2007 2:49 PM

All replies

  • very big troubles
    Wednesday, May 30, 2007 9:44 AM
  • Have you tried to "Freeze" it? I'm not sure if that will work.

     

    Also, can you reuse them rather than create new ones? Are you releasing all references to the WriteableBitmap once you're done with it? The GC should clean it up once all references are gone.

    Wednesday, May 30, 2007 12:48 PM
  • Freeze doesn't work Sad And there is a situation when image size are diffrent. GC.Collect and references are released.
    Wednesday, May 30, 2007 1:29 PM
  • Can you isolate the problem to just the WriteableBitmap -- leaving out the DICOM, etc.? Can you confirm all references are released by using either WinDbg or a .NET Profiler (the CLR profiler for .NET 2.0 is free from Microsoft)? Sometimes it's easy to miss cases where there are attached events, thus objects aren't eligible for GC.
    Wednesday, May 30, 2007 2:02 PM
  • I have only 3 lines of code using WritableBitmap ...

    Code Snippet

    writableBitmap = new WriteableBitmap(imageBufferBGRA.Width, imageBufferBGRA.Height, 96, 96, PixelFormats.Bgr32, null);


    writableBitmap.WritePixels(new Int32Rect(0, 0, imageBufferBGRA.Width, imageBufferBGRA.Height), imageBufferBGRA.Pointer, imageBufferBGRA.MemBuffer.Length, imageBufferBGRA.Pitch);

    showImage.Source = writableBitmap;



    //and in Unloaded event

    showImage.Source = null;

    writableBitmap = null;



    if i comment lines of initialization WriteableBitmap showImage.Source always is null. And memory allocations about 50 mb even when i'm loading all dicom disk in cycle (3 GB imagebuffers allocated and disposed)
    Wednesday, May 30, 2007 2:35 PM
  • YES! I find mistake. I have DispatcherTimer on my UserControl with showImage. Timer should be stopped inside unloaded event! And it was great! It's work. But it's realy strange, becouse i'm releasing showImage.Source reference in unloaded event. Thanks!
    Wednesday, May 30, 2007 2:49 PM