Duct tape, debugging, and you!

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 2494 Views - Last Post: 18 August 2010 - 07:08 AM Rate Topic: -----

#1 maklaka  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 15-June 10

Duct tape, debugging, and you!

Posted 10 August 2010 - 08:01 AM

Environment: Visual Studio 2008, .NET 3.5, C#, Winform.

Okay, so I'm working on a little project that is essentially complete. However, I've discovered an unfortunate memory leak that grows when the main form has focus, but not when any other application has focus. Using ANTS Memory Profiler I can definitely see that the number of object instances grows; the rate being about 1MB/second if you take the task manager's word for it. Is this behavior indicative of any noob mistakes in managed code or might my err be found in the intricacies of my not-so-skillfully crafted work?

Assuming the latter, I took the liberty of placing a break point at the top of every single method,property and constructor of my program. To may dismay, the debugger is not tripping over any of them while the memory grows veritably and rapidly.

Are there any tips or sage advice you pros are willing to grace me with?

This post has been edited by maklaka: 10 August 2010 - 08:02 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Duct tape, debugging, and you!

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:04 AM

Start it and wait for the exception :) It should give you an idea where it is when it's creating a new object.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5626
  • View blog
  • Posts: 12,070
  • Joined: 02-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:06 AM

Quote

the rate being about 1MB/second if you take

Let me guess... you have a timer going at approx. 1000ms. Maybe to update an on-screen clock, or check a file directory every 1 second. What else are you doing in that timer_tick handler?
Was This Post Helpful? 0
  • +
  • -

#4 maklaka  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 15-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:19 AM

View PosttlhIn, on 10 August 2010 - 07:06 AM, said:

Quote

the rate being about 1MB/second if you take

Let me guess... you have a timer going at approx. 1000ms. Maybe to update an on-screen clock, or check a file directory every 1 second. What else are you doing in that timer_tick handler?



Unfortunately, no. All of my timers are inactive on first load but the problem exists anyways.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:21 AM

any other loops during the load?
Was This Post Helpful? 0
  • +
  • -

#6 maklaka  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 15-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:25 AM

View Posteclipsed4utoo, on 10 August 2010 - 07:21 AM, said:

any other loops during the load?



Nothing that my copious breakpoints would have missed or for that matter be running only when the form has focus.

View PostMomerath, on 10 August 2010 - 07:04 AM, said:

Start it and wait for the exception :) It should give you an idea where it is when it's creating a new object.



Not quite sure of your meaning.
Was This Post Helpful? 0
  • +
  • -

#7 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:29 AM

View Postmaklaka, on 10 August 2010 - 06:25 AM, said:

View PostMomerath, on 10 August 2010 - 07:04 AM, said:

Start it and wait for the exception :) It should give you an idea where it is when it's creating a new object.

Not quite sure of your meaning.

Eventually your system will run out of memory and the program will throw an exception when it does. At that point, it will show you where in the code it was when it threw the exception and you'll have an idea what it was doing.

Something just came to mind, are you running 2010 Pro or higher? Could it be the new debugging trace that is using up your memory?
Was This Post Helpful? 0
  • +
  • -

#8 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • View blog
  • Posts: 552
  • Joined: 07-July 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:30 AM

Eventually the memory leak will cause a crash because your system will run out of memory. The debugger will tell you what caused the crash. If the program is "doing nothing", the crash report will show where an object is being created. There is your memory leak.
Was This Post Helpful? 0
  • +
  • -

#9 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:32 AM

Are you using threads? This can sometimes make the debugger miss breakpoints.

Try to go through your code and replace variable declarations with using blocks, this should then dispose of said variables/objects.

ie, turn this into this etc

Type name = new Type();
name.DoSomething();



using (Type name = new Type())
{
    name.DoSomething();
}



If this doesn't help or you have far too many, then is it possible for you to only enable certain parts of the code? If so, start to shut bits down, until the problem goes. Process of elimination can sometimes work.

Are you using managed or unmanaged code?
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5626
  • View blog
  • Posts: 12,070
  • Joined: 02-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:32 AM

Quote

I've discovered an unfortunate memory leak that grows when the main form has focus, but not when any other application has focus.


Keep you eyes on the prize. You've narrowed it down to this.

Let's see your custom "on_paint" method.
Was This Post Helpful? 0
  • +
  • -

#11 maklaka  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 15-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:36 AM

View PostMomerath, on 10 August 2010 - 07:29 AM, said:

View Postmaklaka, on 10 August 2010 - 06:25 AM, said:

View PostMomerath, on 10 August 2010 - 07:04 AM, said:

Start it and wait for the exception :) It should give you an idea where it is when it's creating a new object.

Not quite sure of your meaning.

Eventually your system will run out of memory and the program will throw an exception when it does. At that point, it will show you where in the code it was when it threw the exception and you'll have an idea what it was doing.

Something just came to mind, are you running 2010 Pro or higher? Could it be the new debugging trace that is using up your memory?



Unfortunately that is also not the case because eventually everything seems to be garbage collected once the gluttonous program grows close to 200MB.

View PosttlhIn, on 10 August 2010 - 07:32 AM, said:

Quote

I've discovered an unfortunate memory leak that grows when the main form has focus, but not when any other application has focus.


Keep you eyes on the prize. You've narrowed it down to this.

Let's see your custom "on_paint" method.



Unfortunately I've overridden no on_paint events either :\ Although that was one of my first instincts and I double-checked just to be sure, lol. >.<
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5626
  • View blog
  • Posts: 12,070
  • Joined: 02-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:44 AM

Quote

Something just came to mind, are you running 2010 Pro or higher? Could it be the new debugging trace that is using up your memory?


I've been running 2010 pro for many months and don't see this behavior.
Was This Post Helpful? 0
  • +
  • -

#13 maklaka  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 15-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:51 AM

Here's a thought:

If I am somehow magically garbage collecting around 200MB, is there a way for me to disable GC so that I can see the exception >.> :-\

Attached is a screen shot of the ANTS Memory profiler. Notice the linear increase in memory usage on top during the time I had the form in focus. Also notice the fields that saw the most dramatic increase.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#14 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2270
  • View blog
  • Posts: 9,496
  • Joined: 29-May 08

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 08:58 AM

1000bytes is about 1KiloByte not 1Megabyte
Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5626
  • View blog
  • Posts: 12,070
  • Joined: 02-June 10

Re: Duct tape, debugging, and you!

Posted 10 August 2010 - 09:05 AM

View PostAdamSpeight2008, on 10 August 2010 - 07:58 AM, said:

1000bytes is about 1KiloByte not 1Megabyte


So in reality the program is growing by 1k/sec up to 200k, then garbage collecting?
Big deal. That sounds like normal behavior. 200meg would be an issue. 200k is reaction to every day events from the OS because it is the forground application. It's being asked if it wants to react to the clock ticking, and announcements from other applications.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2