Hi,
Our company has an app that load their components by System.Reflection.Load (By the way, an awesome technique
)
But, we start to monitorate the application and detect a extrange grow up of memory... (actually when our application still all day on air, their allocate memory on task manager is 200 MB plus memory
) And all of our components (60 plus DLLs) is load by this technique.
My doubt is how to deallocate this assemblies or how the best way to deallocate any assemblies loaded by the System.Reflection.Assemblie.Load method
Anyone knows how i can do this
ps.: We use the .Net Framework 1.1. The System.Reflection.Assemblie doesn’t have any "unload" method ![]()
At.,
Fabio Pirani de Padua.

How to UNLOAD an assembly that was loaded by using System.Reflection.Assemblie.Load method???
sani007
First of all, thanks for your attention...
1) - Well, in first place, our application is a commercial app that cares of a Rent a Car business. Write in VB .Net framework v. 1.1;
We use the Crystal Reports .Net to load our reports; We use a third part controls, grid controls; We have five distincts places thats uses our application distributed in our region... So we use a Web Services to communicate with the host central (DB, components, security roles, etc);
But, our (60 plus assemblies) is loaded on client; This assemblies contains windows forms, crystal reports files, resorces like icons, images, etc;
When we start the app on client machine, the app allocate, more or less, 30 MB of memory... And so, at the end of day, the same app increase up to 200 MB plus of memory (monitoring with task manager). When the user open one screen, the win form is in another assembly and this assembly is loaded with Reflection. And the problem occurs only in client machine;
2) - Our first architectury not forecast more than one appdomain cause our team comes from VB 6 technology (we don’t know if develop our app in a single appdomain it was the most correct choice);
3) - No, we just use:
objAssembly = System.Reflection.Assembly.LoadFrom("assemblie.dll")
Are there some different way to load the assemblie I mean, exist any better way to load it
Thanks again,
Fabio.
DOSrelic
Well, since you use reflection just to load the assemblies then this is not much different from adding a reference to that assembly in your project and build it so I don't think the memory usage has something to do with Assembly.Load. As I already stated you cannot unload an assembly unless you are unloading the appdomain in which it was loaded. Adding appdomain is probably not an option. It is quite complicated even if you do it from start especially if you have to deal with an user interface.
I'd say that the memory usage has other sources than Assembly.Load. Try using a memory profiler and see what exactly is using the memory. (For example CLR Profiler from Microsoft, it is a bit rough to use but it does its job and it is free http://www.microsoft.com/downloads/details.aspx familyid=A362781C-3870-43BE-8926-862B40AA0CD0&displaylang=en).
Peter Lillevold
Hi Richard,
I will try with this... I never see it before... I hope so that be useful
Thanks a lot!!!
By the way... we need know how Reflection works with ASP .Net; We will start an e-commerce project in ASP .Net 2005 and we want to use all of the power of Reflection to Load and Unload our components...
Anyone know somethink about it
Thanks again!!!
Fabio.
rchokler
Hi Richard;
Have you any sample about it Cause I already search over internet about this subject and I just found explanation... by the way a lot of poor explanation;
Another doubt; Use this Technique with ASP .Net (over IIS) exist the same problem
Wayne R
Hi fabio,
You probably want to look into doing something along these lines ...
Dim domain As AppDomain = AppDomain.CreateDomain("MySafeDomain") Dim *** As Reflection.Assembly = domain.Load("MyDodgyAssembly") Dim mdt As IDodgyType = CType(***.CreateInstance("MyDodgyType"), IDodgyType)When you want to dispose of the domain simply call AppDomain.Unload(domain)
With regard to ASP I'll have to pass over to someone else to answer that one. I have always stayed well away from it
;
Hope this helps
RIchard
Davids Learning
1) What makes you think that loading the assemblies using Assembly.Load is the cause of this memory usage Perhaps it's just normal memory usage for this application or there are other problems.
2) You cannot unload an assembly unless you unload the whole appdomain (application domain) in which was loaded. If your application was not designed for using application domains you are probably simply loading these assemblies in the default appdomain which cannot be unloaded.
3) If I remember correctly .NET 1.1 did a lot of caching for reflection operations and the cache is never cleared. Are you using somehting other than Assembly.Load from System.Reflection (MethodInfo, PropertyInfo etc.) (Altough I doubt that this can account for 200 megabytes of memory, it depends on how complex are those 60 assemblies).
vats
Hi Fabio
The only technique I am aware of is to initially load the assembly into a separate appdomain and then dispose of that domain when you are finished with it.
There are obvious implications and restrictions on how you can then interact with the satellite assembly, but if you can work around these then this may be an option for you.
Richard
IGiberson
Hi,
The common language runtime loader manages application domains, which are constitute defined boundaries around objects that have the same application scope. This management includes loading each assembly into the appropriate application domain and controlling the memory layout of the type hierarchy within each assembly.
Assemblies contain modules, modules contain types, and types contain members. Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object. You can then invoke the type's methods or access its fields and properties.
I searched an article titled Page Inheritance In ASP.NET in code project and hope that will help you to understand the Reflection:
http://www.codeproject.com/aspnet/AspNetInheritance.asp