C#, Process Memory slowly going up but snapshots not indicating memory leak
Hello, so I've been working on testing pythonnet for use in our companies application and now am doing a stresstest with a wpf application to find and patch any memory leaks.
The program is basically just calling a python function that generates a sinewave and matplot figure of it, and returns the data series and the plot (double[] and byte[]), on the c# the plot is turned into a BitmapImage and set as ImageSource on a Image Control. The problem I am now encountering is that the process memory is slowly increasing, but using the diagnostics tool and looking at he heap size doesn't show any indication of a memory leak.
Pretty new to C# and especially wpf, so maybe I'm simply missing something? The process starts out around 200mb Process Memory and after 15min it's at around 400. Image of the Snapshots and Process Memory attatched, as well as the relevant code snippets in a markdown file
Would be great if someone has some insight into what might be wrong...
15 Replies
if u change this line
to
does anything change?
how do u know the leak is not coming from python?
also your memory will always spike when u get a bigger image in size then the last one
until the GC comes by and acts on it but since you're not disposing of your bitmapimage or using the usings it will remain in your code
thanks for the reply. using on BitmapImage doesn't work, guess it's not IDisposable.
Would be surprised if there were any more leaks in that short python code, anything I don't transfer to c# should be cleaned up by python gc.
I indeed I misread it for a different class let me look at it again
Okay, just provoked a memory leak in python and that doesn't show up on the snapshots. Guess I'm gonna look into the python code, though it is so short I don't really see any potential for any leaks...
yeah I assume it would not show there
but the c# side looks ok aside from the random fact that the memory will increase until the GC comes by to clear what needs to be clear
Thanks for the help, guess it's gonna take some more time digging through everything to find what's causing the problem.
sorry why do u need python
For all the processing libraries. especially opencv, our main application is c#, but most of the computer vision engineers are better at using python for their processing needs.
ok but if they give u the data u can use https://scottplot.net/cookbook/
ScottPlot Cookbooks
Cookbooks or organized by major version
so u avoid a big chunk of issues
instead of plotting on python to copy the image
the plotting was just a easy stresstest of copying image data from python to c#. since we capture the images in c#, we have to move the data to python, there it is processed, segmented, annotated etc and the processed image is moved back to our c# side, so we really need the functionality of moving large data chunks.
but that library looks nice, gonna remember that one
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
It's a stress test, that's probably fine?
I know ScottPlot is the new hotness, but I still like Oxyplot. Easier to use and just as capable (if not more) IMO
It's interesting, I call the gc in python and somehow this also triggers the c# gc