Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

COM and unmanaged memory leak

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
news.microsoft.com - 12 Dec 2004 19:59 GMT
Hello,

I'm using a COM component in a .net program and notice that the memory
allocated by the COM object is never released (with or without GC.Collect),
the memory gets filled in a linear fashion.

Running the same logic in a VB6 application correctly releases the memory!
The memory used by the process stays unchanged.

Is there someone knowing what's going on or knowing a trick to release that
unmanaged memory ?

Thanks,

SChikh

       private void button2_Click(object sender, System.EventArgs e)

       {

           for (int j=0; j<100;j++)

           {

               for (int i=0; i<100;i++)

               {

                   IEis eis = new EisClass();   // <- COM object

                   Marshal.ReleaseComObject(eis);

               }

               GC.Collect();

               GC.WaitForPendingFinalizers();

               Console.WriteLine(">>>>{0} TotalMemory:{1} WorkingSet:{2}
VirtualMemorySize:{3}",

                   j, GC.GetTotalMemory(true),

                   Process.GetCurrentProcess().WorkingSet,

                   Process.GetCurrentProcess().VirtualMemorySize);

           }

       }
zabutimaxim@hotmail.com - 14 Dec 2004 13:55 GMT
Hi,

I think you doing everything right, but you can not
cause to GC to collect immidiatly. I don't know what is
the size of your COM object, but if it is small one, then
you have to wait very long time until GC will actually
collect the garbage. So I propose just for test to create
some COM object with size 20-30MB and you will definatly
will see that virtual memory will grow up and down, up and down...
The problem is just timing of GC collection. If I'm understand right
it start to collect only when there is not enough memory.

Hope this help.

> Hello,
>
[quoted text clipped - 46 lines]
>
>         }
SChikh - 16 Dec 2004 22:55 GMT
Hi zabutimaxim, thanks for your help

Sorry for my late reply but had a hard time fitting with other issues with
my application.

Don't know really what's inside the COM object but running the code for half
an hour, the working-set and virtual memory usages get 3 times bigger (in
task manager), and never really go down. Running on a server after few days,
the application took more that 1 GB of virtual memory.

Following statistics are coming from the application process object
properties:
                                            Start
after 30 minutes
                                        --------------         ------------
--------
WorkingSet:                         42,352,640              77,643,776
VirtualMemorySize:           184,360,960            209,412,096
PagedMemorySize:              25,321,472              60,436,480
PagedSystemMemorySize:         88,836                      83,052
NonpagedSystemMemorySize:   16,344                      14,912

According to following thread there may be a bug in the .net 1.1 about
memory leak, has someone more info on that, is there anything I can do to
reduce that memory consumption ?

http://groups.google.be/groups?hl=fr&lr=&threadm=eogdroX9DHA.696%40tk2msftngp13.
phx.gbl&rnum=6&prev=/groups%3Fq%3DMaxWorkingSet%26hl%3Dfr%26lr%3D%26selm%3Deogdr
oX9DHA.696%2540tk2msftngp13.phx.gbl%26rnum%3D6


SChikh
zabutimaxim@hotmail.com - 20 Dec 2004 13:52 GMT
Hi,

I would suggest you to check if the COM you using has memory leaks.
Just write some test application in unmanaged language (VB 6.0 or
Delphi or C++)
that creates in inifinite loop the object, uses same methods that you
use in your
managed code and release the object. Put this test to work for night
and monitor
the Virtual Memory and Private Bytes perfmon counters. Be carefull not
to create
memory leaks in your own test, because it will confuse your analyzing.
For example if your test will write log information into some ListBox
control
then memory will grow up not because COM object, but because your
test:))

Hope this helps.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.