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 / CLR / October 2003

Tip: Looking for answers? Try searching our database.

Question on Assembly Loading and Memory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick Strahl [MVP] - 03 Oct 2003 20:06 GMT
Hi all,

I have a fairly open question in regards how memory usage is affected by
linking in various assemblies.

Basically I seem to remember that the .net runtime compiles code as it uses
it, so if there's some unused code inside of my own assemblies that code may
never get loaded or even compiled for that matter. What is granularity that
.Net chooses here? Is it based on per method basis, per class, per assembly?

Along the same lines how and when are assembly references resolved? For
example, assume I have an application that links to a logging module. This
logging module in turn links to another assembly that contains email
support. If I don't use the Email support in this app, is the email code
never loaded and furthermore would the code startup and run if the assembly
DLL is not there?

+++ Rick ---

Signature

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
----------------------------------
Making waves on the Web

Mattias Sj?gren - 04 Oct 2003 02:21 GMT
Rick,

>Basically I seem to remember that the .net runtime compiles code as it uses
>it, so if there's some unused code inside of my own assemblies that code may
>never get loaded or even compiled for that matter. What is granularity that
>.Net chooses here? Is it based on per method basis, per class, per assembly?

I'm pretty sure JIT compilation happens on a per method basis, but I
can't find anything to confirm it at the moment.

>Along the same lines how and when are assembly references resolved?

Lazily, on first use.

>For
>example, assume I have an application that links to a logging module. This
>logging module in turn links to another assembly that contains email
>support. If I don't use the Email support in this app, is the email code
>never loaded and furthermore would the code startup and run if the assembly
>DLL is not there?

It depends on how the logging module is written. If the parts that
need the e-mail support are well isolated so that none of the types or
methods that use the e-mail component are loaded / jitted, the e-mail
assembly shouldn't have to be loaded.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Rick Strahl [MVP] - 04 Oct 2003 05:50 GMT
THanks Mattias,

That's kind of what I've come up with in my informal tests. It seems from a
perspective of memory usage and loading unneccesary stuff .Net is doing
really well...

However, I also seem to remember a number of people recommended to be really
careful about assembly references added to projects and try to minimze to
keep load size etc. down. Assuming you use a component only for a very
specific feature then it appears there's little overhead for doing so...

FOr example, one thing I always squeamed at was using
System.Web.HttpUtility.UrlEncode() in fear of pulling in System.Web. The
dependency is otehr than that the overhead of using a simple function like
that should be minmal.

It's funny I remember reading up on this stuff a few years back, but I can't
remember it nor where... wasn't ready to assimilate at the time <g>...

+++ Rick ---

Signature

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
----------------------------------
Making waves on the Web

> Rick,
>
[quoted text clipped - 23 lines]
>
> Mattias
Ori Gershony [MSFT] - 06 Oct 2003 23:01 GMT

Mattias has it right.  The CLR tries to be as lazy as possible with regard
to loading of modules, types, and methods.  There is a small per-module,
per-class, and per-method overhead that you incur just once as soon as the
respective module, class, or method is loaded for the first time.

However, it may not be completely obvious when you will incur this
overhead.  For example, when the CLR JITs a method, if that method refers
to a type in another module, that module will need to be loaded at JIT
time.  This will be the case even if the relevant code will never execute
in practice.  Inlining makes it even more difficult to determine exactly
what you are using.

So in general you will get the lazy behavior that you expect, but if you
are relying on this for your performance, I encourage you to measure this
and make sure this module doesn't get loaded in your key scenarios.

-- Ori.

--------------------
>From: "Rick Strahl [MVP]" <rickstrahl@hotmail.com>
>References: <O0jLHGeiDHA.3484@tk2msftngp13.phx.gbl>
<uiFLGXhiDHA.2748@TK2MSFTNGP11.phx.gbl>
>Subject: Re: Question on Assembly Loading and Memory
>Date: Fri, 3 Oct 2003 18:50:20 -1000
[quoted text clipped - 64 lines]
>>
>> Mattias

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note:  For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.


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.