unload image from memory

Oct 23, 2011 at 3:35 PM

How to unload tiff image from memory after image layer is removed from map in DemoMap aplication?

Regards, Vojko

Developer
Oct 24, 2011 at 6:57 PM

Are you asking about releasing the memory or the file handle?

Oct 25, 2011 at 10:41 AM
Edited Oct 27, 2011 at 5:58 PM
I do not know if bellow problems are about releasing the memory or it is about file handling?
 
1. When I remove layer with tif image from map I want to use that image in another aplication. But it can not be used because "it is used by another program".
2. Also when loading third tiff image (each 70Mb) in to map, DemoMap program report this message:
"Out of memory." and "An inhandled Microsoft .NET Framework exception occured in DemoMap.exe [3116]". I am using MS windows XP, 2GB of RAM and DotSpatial_29eb17f63168 set.
 
Any suggestions will be highly appreciated.
 
Thanks for quick answer and regards, Vojko

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Out of memoryw
   at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
   at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
   at DotSpatial.Data.Rasters.GdalExtension.GdalImage.CopyValuesToBitmap() in C:\DotSpatial_29eb17f63168\DotSpatial.Data.Rasters.GdalExtension\DotSpatial.Data.Rasters.GdalExtension\GdalImage.cs:line 953
   at DotSpatial.Data.Rasters.GdalExtension.GdalImage.ReadRgb() in C:\DotSpatial_29eb17f63168\DotSpatial.Data.Rasters.GdalExtension\DotSpatial.Data.Rasters.GdalExtension\GdalImage.cs:line 671
   at DotSpatial.Data.Rasters.GdalExtension.GdalImage.Open() in C:\DotSpatial_29eb17f63168\DotSpatial.Data.Rasters.GdalExtension\DotSpatial.Data.Rasters.GdalExtension\GdalImage.cs:line 226
   at DotSpatial.Data.ImageData.Open(String fileName) in C:\DotSpatial_29eb17f63168\DotSpatial.Data\DotSpatial.Data\ImageData.cs:line 163
   at DotSpatial.Data.Rasters.GdalExtension.GdalImageProvider.OpenFile(String fileName) in C:\DotSpatial_29eb17f63168\DotSpatial.Data.Rasters.GdalExtension\DotSpatial.Data.Rasters.GdalExtension\GdalImageProvider.cs:line 256
   at DotSpatial.Data.Rasters.GdalExtension.GdalImageProvider.DotSpatial.Data.IDataProvider.Open(String fileName) in C:\DotSpatial_29eb17f63168\DotSpatial.Data.Rasters.GdalExtension\DotSpatial.Data.Rasters.GdalExtension\GdalImageProvider.cs:line 164
   at DotSpatial.Data.DataManager.OpenFile(String fileName, Boolean inRam, IProgressHandler progressHandler) in C:\DotSpatial_29eb17f63168\DotSpatial.Data\DotSpatial.Data\DataManager.cs:line 408

Oct 31, 2011 at 10:46 AM

Hi mudnug,
thank you for your first feedback. Any help for my above problems is greatly appreciated. I do not know how to handle them? Are 4 or 5 images each 70 MB loaded into map to much for DSP aplication?  
Regards, Vojko

Developer
Oct 31, 2011 at 6:04 PM

1. Is due to unresolved bugs in the Gdal extension. 

2. Is probably due to memory fragmentation and also needs to be addressed.

Developer
Oct 31, 2011 at 6:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 11, 2012 at 8:04 AM

Hi all, 

 

sorry for resuming this old post, but it is of my interest.

The problem is that the link to the work item indicated by mudnug is (I guess) expired.

Did you solve the above problem? Is there a discussion where you developed the discussion?

 

Thank you

Oscar

Nov 11, 2012 at 9:18 AM

Hi, I still have no answer about that, it is further of my inerest
regards, Vojko
----- Original Message -----
From: [email removed]
To: [email removed]
Sent: Sunday, November 11, 2012 10:05 AM
Subject: Re: unload image from memory [DotSpatial:276886]

From: oscarafone77

Hi all,

sorry for resuming this old post, but it is of my interest.

The problem is that the link to the work item indicated by mudnug is (I guess) expired.

Did you solve the above problem? Is there a discussion where you developed the discussion?

Thank you

Oscar

Nov 12, 2012 at 7:21 AM

Thank you Vojko

It seems like after layer removing the file remains open and memory allocated.

Do you know where in the dotspatial source are the methods related to layers removal from the menu accessible from the legend box?

Thank you

Oscar

Nov 12, 2012 at 8:02 AM

Going through the source code I found that the "remove layer" in the legend contextmenu points at a RemoveItem method which I found in

dotspatial.topology.index.strtree.abstractsttree, but I don't know if it is the correct one. Here the code 

        private static bool RemoveItem(AbstractNode node, object item)
        {
            IBoundable childToRemove = null;
            for (IEnumerator i = node.ChildBoundables.GetEnumerator(); i.MoveNext(); )
            {
                IBoundable childBoundable = (IBoundable)i.Current;
                if (childBoundable is ItemBoundable)
                    if (((ItemBoundable)childBoundable).Item == item)
                        childToRemove = childBoundable;
            }
            if (childToRemove != null)
            {
                node.ChildBoundables.Remove(childToRemove);
                return true;
            }
            return false;
        }

 

I don't know C#, so maybe I am completely wrong, though if this is the correct code handling the remove layer menu item, 

it seems that this code simply remove the item from the tree. If I am true, this means that the layer is only removed from the tree

but data connection is still open.

Anyone can help?

 

Thank you

Oscar