So I have a program that I would like to run every hour. All the code I need is in Email.Run() which I execute in the main. Looking online I found a solution that I pieced together for a timer. My problem is that my program will accumulate an enormous amount of memory and CPU after about 30-45 minutes of running. I've been looking into garbage collection and haven't found much help there, besides that the system should do it all on its own. I've heard that the library Timer is a bit outdated? I'm starting here because I don't think there's a problem with how my Run() method performs. I think the main method is performing too many behind the scene "checks" of the time maybe. I don't see anything wrong with my code but can anyone provide any insight or other coding techniques to perform this every hour method?I also looked into threading but I want to know if that would be the solution or not. I would still need to include a timer in the thread and I think that maybe that's where my logic is going wrong.
I don't see anything in that code that would be a huge CPU or memory hog. Presumably it's in your Email.Run() method (which should be named run(), but the way--by convention, method names start with a lowercase letter), but without seeing it, it's impossible to say.
And even if we could see it, any suggestions would probably be just guesses. The proper way to diagnose memory and CPU bloat is not by staring at code and guessing, but by using a profiler.
posted 5 years ago
That is what I just started doing in Netbeans. Good call on the convention also. I'll see if I can tinker with it more and come up with something after some monitoring.