Memory Leak

G

Greg

Anyone know of a good program for locating memory leaks? I've been double
checking my code and I'm not seeing anywhere that I'm not freeing objects,
etc after using them but memory keeps going up and up. It gets as high as
300MB within a couple hours when it starts off at 20MB. I have a lot of
code and use Microsoft SQL Server heavily. Frequently I use arrays,
SqlClient objects, and RegEx. I use dispose with anything that has it and =
nothing for everything else.

Each function that talks to the DB creates and free's its own connection and
objects. I'm wondering if this is part of the problem because it creates
and frees the sqlconnection, sqlcommand, and sqldatareader many times per
minute (not really the most efficient thing to do). I've tried calling
GC.Collect() every 30 seconds but it doesn't look like that's helping, which
makes wonder if things are really being freed.

Am I missing something?
 
C

CJ Taylor

Don't believe task manager. It's not really good measurement of memory your
using.

-CJ
 
G

Greg

CJ Taylor said:
Don't believe task manager. It's not really good measurement of memory your
using.

I've heard that before, but I'm not sure I believe that. It doesn't make
sense for Microsoft to include that if the numbers are all innacurate. Were
not talking a few megs here, but 300MB's. Additionally, the app gets to the
point where it starts getting System.OutOfMemoryException's.

The SciTech .NET Memory Profiler shows that the app memory keeps going up
and also shows that Gen #0 GC keeps going up but never goes down.
 
M

Michael S. Malley

Greg said:
Anyone know of a good program for locating memory leaks? I've been double
checking my code and I'm not seeing anywhere that I'm not freeing objects,
etc after using them but memory keeps going up and up. It gets as high as
300MB within a couple hours when it starts off at 20MB. I have a lot of

Greg,

Are you using Application.EnableVisualStyles? If so and you have any
Application.DoEvents calls, you will lose memory very fast. See my posted
article "NotifyIcon Bug, Application.EnableVisualStyles,
Application.DoEvents, and Memory Leaks."

Michael S. Malley
 
B

Bernie Yaeger

Hi Mike,

I read your article and thanks for the info. But in most of your code you
are looping through application.doevents. Realistically, if I call appdo
say, 150 times, while I have a system open, what kind of memory loss can I
expect? If you lost a meg every 5 seconds, I'd suspect you looped through
appdo thousands of times.

Tx for any advice.

Bernie Yaeger
 
M

Michael S. Malley

Bernie Yaeger said:
Hi Mike,

I read your article and thanks for the info. But in most of your code you
are looping through application.doevents. Realistically, if I call appdo
say, 150 times, while I have a system open, what kind of memory loss can I
expect? If you lost a meg every 5 seconds, I'd suspect you looped through
appdo thousands of times.

Bernie,

I didn't do any type of count on the iterations, but it would be pretty easy
to calculate it based on the code I posted. You are right though--I am
certain it was thousands of calls.

Michael S. Malley
 
G

Greg

Michael S. Malley said:
Greg,

Are you using Application.EnableVisualStyles? If so and you have any
Application.DoEvents calls, you will lose memory very fast. See my posted
article "NotifyIcon Bug, Application.EnableVisualStyles,
Application.DoEvents, and Memory Leaks."

Michael S. Malley

Michael,

Unfortunately I'm not.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top