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 / June 2005

Tip: Looking for answers? Try searching our database.

AppDomain.Unload leaks ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
greg - 12 Jun 2005 05:25 GMT
Hi all,

Can anyone tell me why the code below leaks?
Here is what I do:
1) create new AppDomain
2) create an instance of AppDomain2Class in it,
3) call a AppDomain2Class.Run() method
4) unload AppDomain
No additional assemblies are involved ( even if they were, unloading
AppDomain
supposed to unload all assemblies loaded in it)

Using PerfMon I can see that every call to
appDomain2.CreateInstanceAndUnwrap()
increases .NET CLR Loading "Current Classes Loaded" performance counter up
to 1 class
and it is never recovers back even after appdomain is unloaded

Also every 1000 iterations of the for loop looses around 525K of memory.

Is there something I missing here?

I am running this test under Windows XP SP2
.NET framework version: 1.1.4322.573

Cheers

Greg Volpert

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
namespace AppDomainTest
{
   class AppDomain1Class
   {
       [STAThread]
       static void Main(string[] args)
       {
           for (int counter = 0 ; counter < 1000 ; counter++ )
           {
               Console.WriteLine( counter.ToString() );
               AppDomain appDomain2 = null;
               try
               {
                   // 1. Creating the new appdomain:
                   appDomain2 = AppDomain.CreateDomain("AppDomain2", null, null);

                   // 2. Creating an AppDomain2Class object in the new AppDomain
                   // and returning the proxy to it:
                   string strAssemlyName = typeof(AppDomain2Class).Assembly.GetName().Name;
                   string strTypeName = typeof(AppDomain2Class).FullName;
                   AppDomain2Class objTest = (AppDomain2Class)appDomain2.CreateInstanceAndUnwrap( strAssemlyName, strTypeName );

                   // 3. Calling the AppDomain2Class.Run() method remotely:
                   objTest.Run();
               }
               finally
               {
                   // 4. Unloading appdomain and all its assemblies:
                   if ( appDomain2 != null )
                       AppDomain.Unload( appDomain2 );
               }
           }
       }
   }

   public class AppDomain2Class : MarshalByRefObject
   {
       ~AppDomain2Class()
       {
           // this is being called by GC, so it's not AppDomain2Class that is leaking
       }

       public void Run()
       {
       }
   }
}
Willy Denoyette [MVP] - 13 Jun 2005 21:27 GMT
Please don't multi-post, your question has been answered in
dotnet.framework.

Willy.

> Hi all,
>
[quoted text clipped - 81 lines]
>    }
> }

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.