1

I have an application in C# which reserves too much memory when it wasn't supposed to. The executable is ~100Kb and the whole application is a couple thousands lines of code.
It's main component, has a timer which is responsible of creating events (instances of a class with a couple of attributes) and sending them to this http://timeline.codeplex.com/. The way the timeline accepts events, is by calling a ResetEvents function and passing a list of events. Because I have a timer, I put that inside the timer's code.
Running it like this, the application goes up to 300Mb of memory and I just end it to avoid crashing. If I remove the call of ResetEvents from the timer, then the application runs more smoothly consuming 60-70Mb. The application without the timeline, should run at 10-20Mb. There are no graphics or anything that could possibly use more than that. My guess is that something might be wrong with the timeline.

EDIT:

Here's a part of the code:

List<TimelineEvent> events = new List<TimelineEvent>();

...

inside timer

TimelineLibrary.TimelineEvent newevent = new TimelineLibrary.TimelineEvent();
...
newevent.StartDate = starttime;
newevent.EndDate = endtime;
newevent.Id = id;
newevent.Title = title;
newevent.Description = description;
newevent.Link = url;
newevent.EventColor = color;

events.Add(newevent);

timeline.ResetEvents(events);

...

This code is inside the timer. I just create a TimelineEvent, add it to a list and call ResetEvents. Removing that last line, doesn't cause the memory problem.

H H
  • 263,252
  • 30
  • 330
  • 514
user579674
  • 2,159
  • 6
  • 30
  • 40
  • 3
    Sounds like you should post some code and also sounds like you have a manged leak... – Stormenet May 22 '11 at 17:18
  • 1. Any clues about what's wrong? 2. Is it certain that there is a problem with the timeline or is there a chance that something else is going on 3. Anyone who used that timeline, encoutered similar problems? – user579674 May 22 '11 at 17:20
  • I can't post 2k lines here but as I said the problem arises by calling ResetEvents again and again inside the timer. Everything else is irrelevent with the timeline and the only thing that is relevant is a list of TimelineEvents (as defined by the timeline itself). So inside the timer, I just create a new event add it to the list and call ResetEvents.. Maybe my question is particular and related to the mentioned timeline so someone familiar with it will know what I'm talking about. – user579674 May 22 '11 at 17:32
  • If you *do* have a memory leak, the only way to find out is examining the source code. And I can't see it on your screen from where I'm sitting. What type of answers are you hoping for? – Cody Gray - on strike May 22 '11 at 17:33
  • Assuming that the problem is with the timeline, I'm hoping an answer from someone who worked with it and had similar problems.. Also, I don't know what's going on inside the timeline. – user579674 May 22 '11 at 17:34
  • Why guess? Have you tried memory profilers? – oleksii May 22 '11 at 18:02
  • Yes I tried to use one but I don't know what I'm looking at. How can I use them? – user579674 May 22 '11 at 18:04
  • 7
    You should post an (outline of) ResetEvents. The code you did post is totally irrelevant and innocent. – H H May 22 '11 at 18:20
  • What confuses me...the project is a WPF / Silverlight project, yet you do a Winforms app? – flq May 22 '11 at 18:55
  • Actually the project is WinForms but I had to include WPF in order to use the timeline. – user579674 May 22 '11 at 19:40

2 Answers2

2

Since it is very hard to see what your problem is without more code, I suggest trying some kind of memory profiler to locate where and when the memory gets allocated.

Try for example RedGates Memory Profiler, they have a time-based trial.
Follow this walk-through to get up to speed and learn a bit what to look for and how.

For more options regarding .NET memory profilers, see this thread.

Good luck!

Community
  • 1
  • 1
Jakob Möllås
  • 4,239
  • 3
  • 33
  • 61
0

What is the type of the events variable you passed to ResetEvents?

Without seeing the code, the only suspicious behavior I can in what you did post, is that perhaps the ResetEvents method does not really clear the collection it receives, but instead does something on the state of the timeline variable.

Using a memory profiler is a great idea. If you expect people here to help you find a memory leak otherwise, please post more of your code. Ideally, you could reproduce the problem with minimal code and then post that.

Ran
  • 5,989
  • 1
  • 24
  • 26
  • Their type is TimelineEvent as defined in the timeline. I don't know what ResetEvent does since I imported the timeline as a library. – user579674 May 23 '11 at 08:24