Releasing Memory after removing Images.

Aug 2, 2011 at 9:22 PM

I have an application I've developed for 2D aquatic habitat modeling and it is working great.  The application loads 18 grids and converts these to images so that I can define a color ramp.  The images are 32bit floating point geotiffs which are relatively small (1000 x 1400 pixels).  As the user selects different species and life stages the last 18 images are removed from the map and a new 18 are added.  What I've noticed is that the application does not release the memory after removing the images.  This eventually creates a problems as the memory usage keeps going up.  Is there something special I should do to free this memory up, or is there some other means of rotating out my 18 images?  For example the business of opening a grid, converting it to an image with a defined colorramp and then displaying that image is slow.  Should I be doing this another way?

Below is my code for converting the grids to images with a colorramp and adding them to the map. 

        
 	clearlayers()
	For Each pair In flowDict
            fileName = createFileName(pair.Key)
            tmpGrd = New MapWinGIS.Grid

            tmpGrd.SetInvalidValuesToNodata(tmpGrd.Minimum, 0.0)
            tmpGrd.Open(fileName)

            tmpImg = New MapWinGIS.Image
            tmpImg = utils.GridToImage(tmpGrd, colorScheme)
            tmpImg.UseTransparencyColor = True
            tmpImg.TransparencyColor = Convert.ToUInt32(RGB(0, 0, 0))
            tmpImg.UpsamplingMode = MapWinGIS.tkInterpolationMode.imNone
            tmpImg.AllowHillshade = False
            ' tmpImg.TransparencyPercent = 0.9

            hnd = Legend1.Layers.Add(tmpImg, False)
            imgDict.Add(fileName, hnd)
            mapImages.Add(tmpImg)

            Legend1.Map.LayerName(hnd) = fileName
            Legend1.Layers.ItemByHandle(hnd).Type = MapWindow.Interfaces.eLayerType.Grid
            'Legend1.Map.SetImageLayerColorScheme(hnd, colorScheme)
            AxMap1.SetImageLayerColorScheme(hnd, colorScheme)
            Legend1.Layers.ItemByHandle(hnd).Refresh()
            tmpGrd.Close()
            pbLoadingData.Value += 1
        Next

 

And my code to remove the images which get's called before the above:

    Private Sub clearlayers()
        'Clears all the dynamic images from the map
        Dim pair As KeyValuePair(Of String, Integer)
        For Each pair In imgDict
            'AxMap1.RemoveLayer(pair.Value)
            Legend1.Layers.Remove(pair.Value)

        Next
        imgDict.Clear()

        For Each img As MapWinGIS.Image In mapImages
            img.Close()
        Next

    End Sub

 

Thanks for any help, and thankyou for your great work.

 

Colin Talbert

USGS Fort Collins Science Center

 

Developer
Aug 8, 2011 at 2:05 AM

Do  you use the latest version of ocx? Some memory leaking was fixed several months ago. 

I uploaded my today's binaries here: http://mapwingis.codeplex.com/releases/view/56060

In case it's still an issue, could you create a short sample code that reproduces it?

>Should I be doing this another way?

I haven't worked with grids much, so can't suggest anything here.

Regards,

Sergei

Aug 17, 2011 at 11:08 PM
Hello Sergei,
I was on the 4.7 version of the OCX. I installed the newest version that you suggested and my problem went completely away!

Thanks for you suggestion and thanks for all your hard work on this fantastic product!

Colin


Colin Talbert
GIS Specialist
US Geological Survey - Fort Collins Science Center
2150 Centre Ave. Bldg. C
Fort Collins, CO 80526

(970) 226-9425
talbertc@usgs.gov



From: "sleschinski" <notifications@codeplex.com>
To: talbertc@usgs.gov
Date: 08/07/2011 07:05 PM
Subject: Re: Releasing Memory after removing Images. [mapwingis:267498]





From: sleschinski

Do you use the latest version of ocx? Some memory leaking was fixed several months ago.

I uploaded my today's binaries here: http://mapwingis.codeplex.com/releases/view/56060

In case it's still an issue, could you create a short sample code that reproduces it?

>Should I be doing this another way?

I haven't worked with grids much, so can't suggest anything here.

Regards,

Sergei

Read the full discussion online.

To add a post to this discussion, reply to this email (mapwingis@discussions.codeplex.com)

To start a new discussion for this project, email mapwingis@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com