Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, July 11, 2005 10:59:24 AM(UTC)
rbuzzard1

Groups: Registered
Posts: 2


I am new to LeadTools, and am trying to use the Raster Imaging Pro .Net class libraries in a simple image conversion application written in C#. The short version is that I'm pulling index data from a db that includes pointers to a tiff image that is stored out on a file system. I'm looping through the db records, loading the image files one at a time, and appending them to a new image file using the RasterCodecs.Load() and the RasterCodecs.Save() methods. I'm calling the RasterImage.Dispose method after saving the image, but it doesn't appear that the memory is being properly released. Running a memory profiler shows that there are instances of BitmapHandle, WinBitmapInfo, and WinBitmapInfoHeader classes that do not get released.

A simplified example of what i'm doing looks something like this:

protected RasterCodecs codecs;
protected IRasterImage imgPage;

void Init() {
RasterCodecs.CodecsPath = Environment.CurrentDirectory;
codecs =
new RasterCodecs();
imgPage =
null;
}

void WriteData() {
imgPage = null;
for each (pagedata page in pages) {
   if (imgPage==null) { //first page
      imgPage = codecs.Load(imgPath);
      codecs.Save(imgPage, outPath.ToString(), RasterImageFormat.TifCcittGroup4, 1, 1, imgPage.PageCount, 1, CodecsSavePageMode.Overwrite);
      imgPage.Dispose();

   }
   else { //subsequent pages-append
      imgPage = codecs.Load(imgPath);
      codecs.Save(imgPage, outPath.ToString(), RasterImageFormat.TifCcittGroup4, 1, 1, 1, 1, CodecsSavePageMode.Append);
      imgPage.Dispose();


   }

}
imgPage = null;
}

Can anyone tell me if I am doing this inappropriately or why it's not releasing the memory when i dispose the RasterImage object? Is there something i need to do to free up memory? What is the significance of the BitmapHandle, WinBitmapInfo, and WinBitmapInfoHeader classes? Any help on this would be appreciated, as i'm stumped.

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, July 12, 2005 10:48:33 AM(UTC)

Travis  
Travis

Groups: Registered, Tech Support
Posts: 207

Was thanked: 3 time(s) in 3 post(s)

In .NET a Garbage Collector is used to free resources (managed/unmanaged).  This collection process occurs in a separate thread whenever memory is ask for and not enough is available.  However, when in a tight loop new memory is asked for at a very high rate.  In most cases it is ask for faster than the Garbage Collector can keep up with.

So when in a tight loop, you must force a Garbage Collection to take place and have your loop wait for the collection to finish in order to keep from running out of memory.  You do this by calling GC.Collect() and then GC.WaitForPendingFinalizers().  GC.Collect() forces a garbage collection and GC.WaitForPendingFinalizers() forces execution to pause until the garbage collection has finished. 

This should prevent your application from running out of memory.

Travis Montgomery
Senior Sales Engineer
LEAD Logo
 
#3 Posted : Tuesday, July 12, 2005 11:38:49 AM(UTC)
rbuzzard1

Groups: Registered
Posts: 2


Great! Thanks for the info. I had already looked at the Garbage Collection issue, even including the GC.Collect() at the conclusion of each document output, but I was not using the GC.WaitForPendingFinalizers() method. I'm certain it was just not getting finished with the GC each time, thus causing the slow leak. Having added the WaitForPendindFinalizers, it now appears to be managing the memory just perfectly. Thanks for the help!
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.158 seconds.