473,382 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

C# Memory Leaks

Currently our client runs one particular C# .NET executable, and after a few
hours performance slows to a crawl. It would be very useful for me to be
able to rule in (or out) the possibility that this is a result of memory
leakage.

Can someone point me to an article that discusses how bad programming may
produce memory leaks? The application is particularly owner drawn ( so pens,
fonts, and brushes abound - all those things I would
religiously destroy immediately after use in my C++ apps). I never see any
messages in the debugger (a la C++) when the application terminates that
report leaks.

The application also does alot of SQL Server querying - are there disposal
issues there?

I would be particularly interested in any objects that should be disposed of
right after they are used (pens, fonts, arrays, brushes, etc)

I would also be very interested in any tools that will allow me to verify
that a particular .exe (or the DLLs it uses)is/are leaking.

Thank you in advance.
Chris Hough

Nov 15 '05 #1
5 4635
"Valerie Hough" <su*****@hcs-usa.com> wrote in message news:#p*************@TK2MSFTNGP12.phx.gbl...
I would be particularly interested in any objects that should be disposed of
right after they are used (pens, fonts, arrays, brushes, etc)
Pens, brushes and fonts should be disposed of asap but I believe you can rule these out because they will not use much memory. I
can't remember exactly what happens when you run out of say a pen, it will either throw an exception or just draw black. Either way,
running out of pens, brushes or fonts will leave you with plenty of system memory.
I would be particularly interested in any objects that should be disposed of
right after they are used (pens, fonts, arrays, brushes, etc)


You need to dispose/close connections and data readers etc but I wouldn't think this would be the problem either because they should
dispose of themselves sooner or later (sooner if your system in running out of memory).

Do you use images at all? I have a memory leak in one of my apps when importing a large number of pictures into the database. I'm
not sure what causes it as I haven't got around to looking at it yet.

--
Michael Culley
Nov 15 '05 #2
Hi,
First - destroy (dispose) all allocated pens, brushes, icons etc.
If X implements IDisposable, and you got it through "new" operator - call
Dispose when you are going to abandon referenced object.
Second - more subtile problem - is dangling reference. If your program often
allocates new data structures (i.e. as response to client request), and you
store somewhere reference to this data structures (and you don't need them
after end of the request handling) they won't be freed by GC.
In C++ it would lead to exception when you access this reference, or stay
unnoticed if noone touch them.
In .Net it "eats" resources - you have or "nullify" all references, or use
WeakReference instead all but one reference if "nullifying" is too
complicated.

--
==============================
Alexander Arlievsky
sa***@mprest.com
"The best tools for debugging are brains"
==============================

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
"Valerie Hough" <su*****@hcs-usa.com> wrote in message news:#p*************@TK2MSFTNGP12.phx.gbl...
I would be particularly interested in any objects that should be disposed of right after they are used (pens, fonts, arrays, brushes, etc)


Pens, brushes and fonts should be disposed of asap but I believe you can

rule these out because they will not use much memory. I can't remember exactly what happens when you run out of say a pen, it will either throw an exception or just draw black. Either way, running out of pens, brushes or fonts will leave you with plenty of system memory.
I would be particularly interested in any objects that should be disposed of right after they are used (pens, fonts, arrays, brushes, etc)
You need to dispose/close connections and data readers etc but I wouldn't

think this would be the problem either because they should dispose of themselves sooner or later (sooner if your system in running out of memory).
Do you use images at all? I have a memory leak in one of my apps when importing a large number of pictures into the database. I'm not sure what causes it as I haven't got around to looking at it yet.

--
Michael Culley

Nov 15 '05 #3
Yes, I do use images. The software puts up a background image for the main
window, and it is a very large image indeed (full screen picture). Also, the
user comes back to this window over and over in the course of the day,
causing it to be loaded each time. I will certainly look into this. Thanks
alot!
Nov 15 '05 #4
"Valerie Hough" <su*****@hcs-usa.com> wrote in message news:eW*************@tk2msftngp13.phx.gbl...
Yes, I do use images. The software puts up a background image for the main
window, and it is a very large image indeed (full screen picture). Also, the
user comes back to this window over and over in the course of the day,
causing it to be loaded each time. I will certainly look into this. Thanks
alot!


I'll have a look into the memory leak in my app (it's about time I did) and post the results.

--
Michael Culley
Nov 15 '05 #5
Memory leaks in C#? Read up on this: .Net Garbage Collector / Managed Code
"Valerie Hough" <su*****@hcs-usa.com> wrote in message
news:eW*************@tk2msftngp13.phx.gbl...
Yes, I do use images. The software puts up a background image for the main
window, and it is a very large image indeed (full screen picture). Also, the user comes back to this window over and over in the course of the day,
causing it to be loaded each time. I will certainly look into this. Thanks
alot!

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
0
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have...
4
by: Morten Aune Lyrstad | last post by:
Ok, now I'm officially confused. I have a large project going, which uses a win32 ui library I am developing myself. And I'm getting weird memory leaks. I don't know if I can explain what is going...
2
by: Generic Usenet Account | last post by:
I have been using STL for a long time now, without any problems. Recently we generated a purification report on our software using Rational Purify, and we found some memory leaks. My colleague...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
4
by: ali.jan | last post by:
Hi, It is trivial to load an assembly in a new Application Domain. Is there any way of loading an assembly in a new process? I tried using the Process class like this: Process p = new...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
16
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.