Releasing memory / memory leaks

I was always under the impression that when developing in ASP.Net you don't need to worry about releasing memory i.e. in your pages/functions/subs you can create as many variables/objects as you want, use them and then 'walk away' and let asp clear up the mess - but after doing some browsing on the web there are a number of people who do not this this is the case. Can anyone give me a definative answer on this.

 i.e. if i have something like this at the top of my proc :

 dim mObj as new MyClass

do i have to put mObj = nothing at the end.

What about things like collections - does the same apply ?

Finally are thare any specific things to look at / avoid to ensure that your asp.net app does not contain any memory leaks.

 many thanks in advance

0
hadeno
12/5/2008 11:22:44 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

5 Replies
850 Views

Similar Articles

[PageSpeed] 19

 For common variables you don't have to care. If if the data type is defined inside of a function/method then it will only live as long as that function goes from the top code statement till it gets returned by a return or ends. If you have a class on the other hand you'll want to check whether it has a 'dispose' method. If it does i'd suggest using it when you're done and want to clear it. Most collections do i believe and anything inheriting from IDisposable. With connections to a database, file streams, or anything IO related you'll want to use the .Close() method on most as you dont want to leave any connections to resouces open. The biggest thing you need to keep in mind is that garbage collection does not happen immediatly. It takes some time to come around, and typically starts to become noticeable that it's doing work when your memory footprint starts to get larger. You can explicitly call the garbage collector as it's just GC static class. Don't do this since it's not really advisable as it'll figure out its own best time much better than we can, and as long as you close things or dispose of them you're fine.


______________________________________

Robert Lindley | Sr. Software Engineer - MCP, MCAD
ASTRA Innovations, Ltd. - Better Solutions by Design.

--------------------------------------------------

I like points just as much as the next person. If I helped you out please help me out by marking my response as the ANSWER if or when it is.
0
Rampidbyter
12/5/2008 11:30:10 PM

Thanks for this. Just checked and the collection class does not have a Dispose method so i assume you can just use and abuse.

The vast majority of objects i create are instances of my own classes. I have not implemented any dispose methods on these.

So can i therfore assume that there is very little value in using ANTS to do memory profilling on an ASP.Net application ?

0
hadeno
12/5/2008 11:37:51 PM
check this http://forums.asp.net/p/1338438/2708634.aspx
We All move to our original place.
Don't forget.

Imran Baloch
0
imran_ku07
12/6/2008 5:54:13 AM

If you're using simple data types in your custom collections then you don't really need to worry. Just keep in mind things you add to Session, or ViewState hang around and will take up memory. If you open resources to files or create a lot of classes that are not disposed of (IDisposable) then this can lead to memory usage problems. For the most part ASP.Net is simple in that once the page is unloaded most things, minus Sessions/ViewState, are disposed of and will be removed by garbage collection. Keep in mind the more controls, the more ViewState is used for these controls, and the more you add to Sessions will add up to a bigger footprint on memory.

From the standpoint of testing for better efficiency i wouldn't advise against it. There is nothing wrong with trying to make things work faster through investigating what you're using now. As far as worrying about cleanup or memory leaks it's pretty well under control on the .Net side. Found a little article on ASP.Net Performance Monitoring and it'll help give a little better idea of how to isolate when problems really are occuring.

 http://msdn.microsoft.com/en-us/library/ms972959.aspx


______________________________________

Robert Lindley | Sr. Software Engineer - MCP, MCAD
ASTRA Innovations, Ltd. - Better Solutions by Design.

--------------------------------------------------

I like points just as much as the next person. If I helped you out please help me out by marking my response as the ANSWER if or when it is.
0
Rampidbyter
12/6/2008 9:14:56 PM

 >in ASP.Net you don't need to worry about releasing memory

I suggest you download a copy of FXCOP and run it against your compiled code. This will indicate if you have missing dispose calls. In the example, you show:

 mObj.Dispose()

 


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
TATWORTH
12/10/2008 1:50:13 PM
Reply:

Similar Artilces:

memory, memory, memory
Name: bruce Email: bruceatlmcsoftwaredotcom Product: Firefox Summary: memory, memory, memory Comments: Hi, I run firefox all day like I run Outlook. I open/close a zillion tabs using a single instance of firefox, usually no more than 6 tabs at a time. But I've had 20 tabs open at once while I'm culling the NY Times articles I want to print. Every so often my mouse stops moving. Taskmgr shows firefox has 256 Megs of memory (or something equally large) and is using 95% of the cpu. Why?? Make this nonsense stop! Forget the IE/Firefox/Chrome competition. T...

Memory and More Memory
What's the news on fixing this memory issue with FireFox/Thunderbird. T= he = two biggest memory gulpers I've ever used on any computer-bar none. And= = Why do these Mozilla apps take so long to long. It not worth having the= se = apps as defaults for surfing or email/usenets. How could anyone lauch a= = new internet suite with so much system demand..and through constant = updates, still overlook the memory issues. I'm questioning the integrit= y = of Mozilla these days and Opera 8-9 runs like a scaulded dog. I think I'= ll = stay with O...

Memory Leak, Leak, Leak, Leak.....
All, I have spent a lot of time watching the life being sucked out of my computer as I develop using PB during the day. I can document PB 7.0 8030 leaking memory every time I open and close the library, save an userobject, open a datawindow, etc. Some times the memory comes back when when I close PB, but mostly not. On one occasion I watched a nearly full restoration of available memory after closing Powerbuilder and then MSOutlook. How could MSOutlook release memory? Anyhows, I just had to vent. Is anyone else suffering the slow loss of memory? I don't see a lot of thr...

Memory Leak or memory reconfig?
Memory issues on NW6.5 SP4 2GB of memory GWIA,MTA box with GWAVA I only know of the seg.nlm util used in conjunction with memcalc.exe tool to calculate the proper -u amount. This server does not qualify for this tool though because it has -2gb. Any ideas on how I should calculate the -u amount or should I be looking at another issue? Console messages: ----------------------------------------- 9-05-2006 7:02:48 pm: SERVER-5.70-3707 [nmID=120004] Server logical address space is running low. Increase the available logical space by restarting the server wit...

Excess memory usage, "memory leaks," slow start-up, slow shut-down -- all resolved by clearing Browsing History
Unless the following applies only to myself, it may be useful to others. I found myself having various problems several weeks ago. Firefox was taking 20-30 seconds to open and sometimes 20 or more seconds to close. Shortly after this, and more bothersome, was its use of memory. Whereas I used to open a dozen tabs or more without any problems or great slowdowns, now the same number of tabs might use up all of my memory (512 mb). Once when I looked in Task Manager, memory usage was above 700. Another time I got an operating-system warning/alert about virtual memory. Sometimes the...

Memory leak stealing all available memory
I have PB 7.0.2 8011 and have migrated an app. from PB 6.5 (WinNT) After migrating and compiling, I get an exe that takes 105 MB from Virtual Memory and 55 MB from RAM. I have rebuildt all PBL's and tried to compile on another computer (Win98) with same results Can anyone tip me on what could cause this. ------------------------------ �ge J. Haugstad JOBAK-Data as age@jobak.no ------------------------------ One thing, a memory leak means that the program keeps getting memory from the OS without returning, so it will increase in size over time as the app runs. It is p...

Memory leak? Memory usage grows?
 I've got an application that *SHOULD* do about 250,000 inserts into an oracle database. Each record has around 120 columns.  after about 10,000 inserts i get ContextSwitchDeadlock was detectedMessage: The CLR has been unable to transition from COM context 0x19fe30 to COM context 0x19ffa0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application...

Memory Leaks, VCL Native Memory
Hello Below code is causing a memory leak. AQTime show it as "VCL Native Memory" (__Internal_malloc) which is not released after the execution. So question is how to release those internal mallocs ? I get same mallocs when i add an object in TStringList, Even after deleting that item and releasing the object, The object is no longer in memory but internal malloc of Tstringlist is still there and reported as memory leak at end of program. void someclass:somefunction(void) { time_t t; time(&t); AnsiString tmp = ctime(&t); } in above example "someclas...

Memory Leak or Normal Memory Usage?
I have an ASP.NET application that I am working on and I'm trying to determine if I have a memory leak or if the memory usage I'm seeing is "normal". The reason for my concern is that I'm seeing a slow but (at least for the 12 hours I collected data) steady increase in memory usage of this application.  With a "normal" web site I wouldn't worry about this much but the application in question is something of a control panel application that the client side fires up and runs for an indefinite period of time. Just to be clear, I am talking about client...

superreview requested: [Bug 306785] memory leaks in PQG_ParamGenSeedLen : [Attachment 194622] fix for memory leaks
Julien Pierre <julien.pierre.bugs@sun.com> has asked Robert Relyea <rrelyea@redhat.com> for superreview: Bug 306785: memory leaks in PQG_ParamGenSeedLen https://bugzilla.mozilla.org/show_bug.cgi?id=306785 Attachment 194622: fix for memory leaks https://bugzilla.mozilla.org/attachment.cgi?id=194622&action=edit ------- Additional Comments from Julien Pierre <julien.pierre.bugs@sun.com> I have tested this and verified the 2 leaks are gone. all.sh still passes. I'm not 100% sure that my change in getPQseed is correct . The code was previously freeing and re...

superreview granted: [Bug 306785] memory leaks in PQG_ParamGenSeedLen : [Attachment 194622] fix for memory leaks
Robert Relyea <rrelyea@redhat.com> has granted Julien Pierre <julien.pierre.bugs@sun.com>'s request for superreview: Bug 306785: memory leaks in PQG_ParamGenSeedLen https://bugzilla.mozilla.org/show_bug.cgi?id=306785 Attachment 194622: fix for memory leaks https://bugzilla.mozilla.org/attachment.cgi?id=194622&action=edit ------- Additional Comments from Robert Relyea <rrelyea@redhat.com> Your code is correct wrt getPQseed(). We know seedBytes doesn't change, so it's clearly a waste to allocate each time through. bob ...

EAS eats up my memory (aka memory leak?)
Hi all, I've got one EAS component (in an instance pool), and I call the same function again and again, and it eats up 30-60 MB RAM each time. I guess this is what is called a memory leak. I've never paid much attention to memory before, but obviously I should... But: I cannot solve the problem, and if I had to guess it might have to do something with our heavy use of structures/arrays. The component reads data from a datastore, destroys it, in fact it destroys everything it has worked with, but at no success. I can only say the bigger the array of data, the bigger...

superreview requested: [Bug 429230] memory leak in pkix_CheckCert function : [Attachment 315876] Patch v1(remove debug code that leaks memory)
Alexei Volkov <alexei.volkov.bugs@sun.com> has asked Kai Engert (:kaie) <kengert@redhat.com> for superreview: Bug 429230: memory leak in pkix_CheckCert function https://bugzilla.mozilla.org/show_bug.cgi?id=429230 Attachment 315876: Patch v1(remove debug code that leaks memory) https://bugzilla.mozilla.org/attachment.cgi?id=315876&action=edit ------- Additional Comments from Alexei Volkov <alexei.volkov.bugs@sun.com> Nominating the bug for 3.12.0. checkerCheck(a pointer to pkix_PolicyChecker_Check) will throw an error in case when cert does not pass the che...

superreview granted: [Bug 429230] memory leak in pkix_CheckCert function : [Attachment 315876] Patch v1(remove debug code that leaks memory)
Kai Engert (:kaie) <kengert@redhat.com> has granted Alexei Volkov <alexei.volkov.bugs@sun.com>'s request for superreview: Bug 429230: memory leak in pkix_CheckCert function https://bugzilla.mozilla.org/show_bug.cgi?id=429230 Attachment 315876: Patch v1(remove debug code that leaks memory) https://bugzilla.mozilla.org/attachment.cgi?id=315876&action=edit ------- Additional Comments from Kai Engert (:kaie) <kengert@redhat.com> You remove a lot of code, is that all equivalent to PKIX_CHECK ? ...

Web resources about - Releasing memory / memory leaks - asp.net.getting-started

Gonadotropin-releasing hormone - Wikipedia, the free encyclopedia
Gonadotropin-releasing hormone ( GnRH ), also known as Luteinizing-hormone-releasing hormone ( LHRH ) and luliberin , is a trophic peptide hormone ...

10 tips for releasing your Facebook application, and maximizing growth
So, you’ve got a great new facebook app, and you’re salivating at the prospect of unchecked viral growth? Well, who isn’t. Here’s a few tips ...

Releasing Baby Turtles to the Sea
jurvetson posted a photo: a few hours old, they navigate to the brightness of the sky over sea. 95 sea turtles were released by hand by the ...

MASAAN: Official Trailer - Releasing 24 July - Richa Chadha, Sanjay Mishra, Vicky Kaushal - YouTube
Watch the official trailer of MASAAN, the award-winning film directed by Neeraj Ghaywan. Starring Richa Chadha, Sanjay Mishra, Vicky Kaushal ...

Philippines thanks UAE for releasing prisoners during Ramadan
11 Filipinos were released by Sheikh Mohammed bin Rashid in Dubai last month to mark Ramadan.

Trade unions royal commission accused of not releasing all documents relevant to Dyson Heydon's invite ...
The royal commission into trade union corruption has been accused of failing to release all relevant information its commissioner Dyson Heydon ...


Scott Morrison proposes releasing asylum seekers onto Australian mainland under TPV plan
Asylum seekers who arrived by boat last year could be offered temporary protection visas and allowed to live in the Australian mainland community, ...

Peter Greste: Egypt releasing and deporting jailed Australian journalist, officials say
JAILED Australian journalist Peter Greste has been freed from an Egyptian prison and is on his way home.

Are the Kardashians releasing music?
IN true Kardashians style, the famous sisters have recorded a kitschy music video for their mother’s 60th birthday.

Resources last updated: 12/15/2015 5:58:12 PM