I've recently made a desktop application that communicates with a device at my job.
The general idea of the app is to give the device (oven) a "set temperature" command and after every 10 seconds check the current temperature and display it on a graph using livecharts.
This application is required to run multiple days at a time and I seem to be having a memory leak problem, I think.
What I experience is the application not responding for a while, then it becomes responsive and adds 1 single "log" effect as in LogTemp function every around 1-2 minutes. It should be once every 10 seconds.
Edit: Just read the lines before this edit and I think I was not too clear. It works as it is supposed to work the first few hours. Noticed the performance took a hit only after 24 hours.
After 24 hours of running I came back to find it is using over 800 MB of RAM and it kept growing by the second.
I suspect it MAY have something to do with livecharts but I am not sure by any means. (it ends up with 8640 points of data after 24 hours)
I have no issue disclosing my code and have even minimized the amount of code needed to be shown to around 200 lines in total which are split to a few different functions, but if anyone heard of such an issue with livecharts and/or can suggest a different type of graph library I'd be more than happy to swap it out.
Actually, here's the code, lmao:
https://pastebin.com/YBn5CuD6
Another thing I thought of, could it be that I am adding too many rows to the ListView? We're talking about.. 8640 rows in 24 hours. Might that be something to do with it?
Sorry for the long post, thank you in advance.
For anyone interested, I lowered the sample rate which is responsible for how many points are on the LiveCharts chart and it goes very smooth right now, even after 3 days of running.
(RAM usage was also around 90 MB, which is to be expected from my application)
I believe that was the issue, so I'll mark this as an answer for the next person googling LiveCharts memory-leak.
Related
I am working on creating a game, and I have a pathfinding function that takes about 100 ms. I have 5 enemies, each with this function in the contstructor:
newPath = new System.Threading.Timer((e) => {
getNewPath(); //The function that takes ~100 ms
}, null, 0, 5000);
Now, I am using System.Threading.Timer at an earlier point in the program (to run once every 50 ms just for a step function, to update positions and such). That one works fine, but if I run this function (don't forget I have 5 enemies, so it's running 5 times every 5 seconds), my whole entire computer just freezes. Now I don't have a crappy computer (it's not the best, but it's plenty good for what i'm using it for), so I don't know what the issue is. Even if all timers run one after the other (which they shouldn't do, they should run at the same time), the most it should take is 500ms (or half a second), yet it completely kills my computer, to the point where my mouse doesn't move, I can't Ctrl-Alt-Del, and I have to just hold the power button until it turns off.
I tested putting a simple print function in place of the getNewPath(), and it worked flawlessly and as expected, so I don't really know what the issue is.
My questions are:
What is causing my computer to lock up to the point of having to hold the power button.
Is there something I can use other than System.Threading.Timer that will give me the desired result without completely killing my computer? (Being able to run this function up to ~20 times at once, since it's an MMO and there could potentially be hundreds of enemies that it needs to do pathfinding updates on).
Thanks!
Without knowing the code inside getNewPath(), it is impossible to even guess the reason. And it is hard to believe that is only a simple A* path finding algorithm
Here are some points to start the investigation
What is the CPU usage rate before halt happens? What it is the rate when it happens? Which process has the highest rate?
What is the disk, network, memory usage rate?
Beside the above, does getNewPath consume other resources?
You can print 5 messages. But are they printed before/inside/after getNewPath
Do you have source code for getNewPath? Can you modify code in getNewPath?
Is getNewPath thread safe? Does it create more threads?
There are probably more things to look at. But these should be enough to get you started. And they are necessary for anyone to give meaning suggestions.
I've been working on a DICOM viewer. It is currently working correctly. Furthermore, when I tried to convert the slices to a 3D model the process took about 3-4 minutes. After some profiling, it now takes less than a minute. However, there is something weird about the result of the last performance test I made:
May I know why a brace is consuming that much Performance??
EDIT: the closing brace consumes 1.5% too, so I'm pretty sure it doesn't mean the whole function.
I´m currently working on a c# winform-application, in this application I want to visualize a 2d-matrix as a heat-map. The matrix is altered within another thread roughly 50 times per second.
I do not want to slow down the working thread by the visualization, so I suppose using a lock would be counter-productive. Moreover, the visualization may miss some matrix-changes, updating the visualization a few times per second is sufficient.
I´m unsure how I should proceed and hope someone can point me in the right direction?!
Good day,
I wasn't sure if I should post this on the software or hardware stack; I apologize in advance if this is an invalid question.
I wrote a little application that I am using to make time lapse videos - currently it only takes the pictures using a webcam. I know there are already a few available for download, but none of them did 100% what I wanted, and some of them were a little buggy, so I decided I'd rather create my own.
The interval at which the pictures are taken can be configured anywhere from 5 seconds up. Version 1.x would activate the camera and keep it on while in "Time Lapse Mode" and save images to disc at the specified intervals. This approach proved to be very memory intensive - understandably, in retrospect.
I decided to start from scratch - Version 2.x. This version would keep the camera off and only switch it on when it needed to take a picture, and switch it off again. This approach proved much more efficient. The reason for the minimum limit of 5 second intervals is because the camera takes about 1 second to switch on and then roughly the same amount of time to switch off. Perhaps in the future I could change it to keep the camera on when the interval < 5. For now, however, for what I actually want to use it, this will do perfectly.
When I was little we, as children, were told that switching an incandescent bulb on and off and on and off is not good for the bulb - according to a colleague of mine, reliable in that field, this is true.
This got me thinking. Could it be harmful to my webcam if I switch it on and off at, say, 10 second intervals for, let's say, a day or two? And how would switching on and off compare to keeping the device on for a few days? I don't understand what happens on a hardware level so I can't say.
I suppose I have a couple of options:
Switch the application on and off as required to take the pictures. This could result in the camera being switched a few thousand times a day.
Keep the camera on. This could mean the camera might be active for very long periods of time. What if I want to create a time lapse video over a month? Or even a year? Not to mention the memory problem.
Switch between the two modes. When interval < 2 minutes ? keep on : switch. This seems like the best of both worlds but now I'm faced with the memory problem when interval < 2 minutes
Thank you in advance for any and all comments and suggestions - much appreciated.
Kind regards,
me.
Could it be harmful to my webcam if I switch it on and off at, say, 10 second intervals for, let's say, a day or two?
Switching the camera on and off will have no affect on it's lifespan.
How about keeping it on for long periods of time?
Well that really depends on the camera but for something as low powered as a webcam you should be able to run it for many many years before it begins to fail.
Not sure how you are getting frames from your camera but it should not be extremely memory intensive. Using AForge.NET you can pretty simply grab frames from you camera. Tutorial If you could post your code I could better see how to point you in the direction of optimizing it.
Has any one had any luck with getting good performance out of the built in c# chart running in real time?
I have made a chart with 3 charting areas and 9 series which are all the fast line type. I update in real time points to the series and shift the graphs over once 7 seconds of data has been graphed. All this works fine, however the rate that my graphs update is horribly slow. Sometimes it can take almost a second for the data being fed in to be shown in the graph (and many times i wonder if it is accurately updating my graph with my data since it is so slow and the data changes can be so fast).
I have tried using mychart.Series.SuspendUpdates(), Series.ResumeUpdates(), and Series.Invalidate() as i saw on different posting with no noticeable results.
If anyone could share some insight about ways to optimize I would be truly gracious.( and cutting the number data points is not a valid optimization )
Thanks in advance
OCV
If external libraries is an option, ZedGraph worked great for me when displaying data at 10ms intervals (up to 8 series).
If you really must use the built-in C#, I think you might prevent blocking by separating drawing a data into separate threads.