Archived Forum Post

Index of archived forum posts


Memory leaks from OpenFromMemory function

Dec 05 '12 at 12:58

We are using Chilkat dll(ChilkatDotNet2.dll) for uploading/downloading of zip file(size of around 70 MB). While uploading the Zip content, we are calling OpenFromMemory(Byte[] inData) function which internally calling System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb) function.

Application started throwing System.OutOfMemoryException while calling OpenFromMemory(Byte[] inData) function after some few attempts. So I'm assuming the memory leak occurs in the OpenFromMemory(Byte[] inData) in Chilkat. we tried calling dispose() but that did not fix the leak.

StackTrace: - System.OutOfmemoryException: Insufficient memory to continue the exceution of the program. at System.Runtime.interopService.Marshal.AllocHGlobal(IntPtr cb) at Chilkal.CkMarshal.ManagedToUnmanged(Byte[] x,Int32* lenght) at Chilkat.Zip.OpenFromMemory(Byte[] inData) at eLearnDeployment.Upload.IsZipValid(String courseFoldername, Byte[] content, String&errorText) in e:iisdatawebsitesedeployment.pwcinternal.comDeployUpload.aspx.cs:line 169 at eLearnDeployemnt.Upload.btnUpload_Click(Object sender, EventArgs e) in e:iisdatawebsitesedeployment.pwcinternal.comDeployUpload.aspx.cs:line 94 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.Page.raisePostBackEvent(IPostBackEventHandler sourceControl, Strin eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Oage.Processrequestmain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Please suggest.


If there is truly a memory leak in Chilkat, it should be easy to prove. To do so, follow these steps:

First, make sure you are using the very latest version of the Chilkat component.

Second, write a very very simple C# program that does the following:

  1. Load the contents of a zip archive into a C# byte array.
  2. Write a simple loop for many iterations, perhaps 10,000 iterations.
  3. Within the loop, call OpenFromMemory, passing it the byte array.
  4. After the call to OpenFromMemory (and within the loop), call GC.Collect() followed by GC.WaitForPendingFinalizers().

This should be a very simple program that is standalone, with no extra application code that could possibly be the cause of the memory leak.

Run the program, and monitor the memory usage using the Windows Task Manager. You should not see memory grow.

Finally, please see this about .NET garbage collection: It could very well be that your .NET memory usage grows (without garbage collection being triggered), it is near the limit, and then your app tries to allocate a large chunk that pushes it over the edge. This does not necessarily mean there is a memory leak in Chilkat.