Solved

Memory leak

Posted on 2008-09-29
7
261 Views
Last Modified: 2010-04-15
Experts,

I've developed a service which works fine, however I've noticed the memory usage for the application (whilst there are no processes taking place) incrememt slowly, by about 6k every seven seconds.

I'm concerned that this may cause problems in the long term, and I'd like to find out what could be causing this.  

Should I consider setting the variables to null after the program cycle (while true loop) has completed?
0
Comment
Question by:mhouldridge
  • 3
  • 2
  • 2
7 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22596574
Actually, you should consider not only setting them to null, but also disposing of them whenever possible
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 22596598
Yes where possible if you're not using something you should dispose it.  Certain things don't look like they would cause a problem but if you have a constantly running loop, and objects are being used and then not disposed of, they will simply all be "dumped" into a big pile, and then after the next loop that lot will go in the "pile", and so on.  Basically adding up to a lot of cost and wasted memory.
0
 

Author Comment

by:mhouldridge
ID: 22596678
Hi,

Thanks for the info.  I get problems with integers, attempting to set to null....

With Cannot convert to null error.

Is there a generic method for settings variables of any type to null.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 500 total points
ID: 22596836
There certainly is, here is an example:
int? myIntger = 3;  // Declare the integer with a ? to state that its nullable

myIntger = null; // Then you can just set it to null when necessary
0
 
LVL 21

Expert Comment

by:silemone
ID: 22596851
if your integers are not nullabe, then you can only set them to 0...null is only for objects...
0
 
LVL 21

Expert Comment

by:silemone
ID: 22596870
as angus has shown, making integer type nullable or any primative, you must add a ? behind it...
0
 

Author Comment

by:mhouldridge
ID: 22596899
Hi,

Thanks for the info guys...

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now