QHYCCD

Memory Leak with ASCOM?

Memory Leak with ASCOM?
« on: March 21, 2021, 03:22:38 PM »
I developed a ASCOM based All Sky camera app that uses a QHY5II-M. At some point I fixed some stability issues by fully closing and then reopening the ASCOM driver between each exposure. However, when I recently updated the QHY System Pack from version 20.08.26.19 to 21.03.13.17 I noticed that the program started climbing in memory usage after each exposure until it hit an "out of memory" error. I reverted back to 20.08.26.19 and memory usage is stable again. Below is the code snippet that closes and reopens the ASCOM camera.

Please note that I will soon be adding my new QHY268M as my main imaging camera so I need the new drivers but I also need the QHY5II-M ASCOM driver to not eat memory.

Code: [Select]
                        ACam.StopExposure();
                        ACam.AbortExposure();
                        ACam.Connected = false;
                        ACam.Dispose();
                        ACam = null;
                        Thread.Sleep(250);
                        ACam = new ASCOM.DriverAccess.Camera(CamName);
                        ACam.Connected = true;

Thanks!
Frank

Re: Memory Leak with ASCOM?
« Reply #1 on: March 21, 2021, 08:21:06 PM »
    I need check the source code for ASCOM driver,please wait some time.
Best Regards,
QinXiaoXu

Re: Memory Leak with ASCOM?
« Reply #2 on: March 21, 2021, 11:01:54 PM »
Thank You - I await your findings.

Re: Memory Leak with ASCOM?
« Reply #3 on: March 31, 2021, 10:33:19 PM »
Any update?

Re: Memory Leak with ASCOM?
« Reply #4 on: April 01, 2021, 08:22:34 PM »
Hi,
    I checked the ASCOM driver with  MDL,MDL's call list is:
Code: [Select]
//Connection
Camera
Connect get
SetupDialog
Dispose
Camera
Connect set
//Capture continuously
StartExposure
ImageArray
StartExposure
ImageArray
StartExposure
ImageArray
//StopExposure
AbortExposure
//Disconnection
Connect set
Best Regards,
QinXiaoXu

Re: Memory Leak with ASCOM?
« Reply #5 on: April 02, 2021, 03:30:52 PM »
Some background information: my program is constantly changing exposure and/or gain as it runs and I found this caused lines and streaks and some instability. However, I found that by doing an ACam.Dispose() and restarting the ACam object before each exposure was more stable and the images were cleaner (no lines or streaks).

However, I suspect that 21.03.13.17 ACam.Dispose() call is not properly releasing its memory.



Re: Memory Leak with ASCOM?
« Reply #6 on: April 05, 2021, 09:39:34 PM »
Hi,
    Yes,previously we release camera SDK in Dispose function,now we move it to Connect set function.
Best Regards,
QinXiaoXu

Re: Memory Leak with ASCOM?
« Reply #7 on: April 06, 2021, 09:54:40 PM »
    Yes,previously we release camera SDK in Dispose function,now we move it to Connect set function.
Your statement raises new questions...
Is the "ACam.Connected = false;" (from my code snipet) supposed to release all memory?
Does the Dispose() function do anything?

Please note that 21.03.13.17 still is not releasing memory even after calling both "ACam.Connected = false;" and "ACam.Dispose();"...

Re: Memory Leak with ASCOM?
« Reply #8 on: April 07, 2021, 01:36:05 AM »
Hi,
    I found a issue,if I connect camera,capture one frame and disconnect camera,and repeatedly do this step,this will make used memory more and more.
    It seem this is the same issue with you.
Best Regards,
QinXiaoXu

Re: Memory Leak with ASCOM?
« Reply #9 on: April 07, 2021, 07:05:50 PM »
Yes! That is the issue! I am happy you found it also. Version 20.08.26.19 does not have that issue, it seems to release the memory completely.

Re: Memory Leak with ASCOM?
« Reply #10 on: April 07, 2021, 08:24:40 PM »
    OK,I need take some time to check it,please wait for some time.
Best Regards,
QinXiaoXu

Re: Memory Leak with ASCOM?
« Reply #11 on: April 08, 2021, 10:00:34 PM »
Thank you! I hope you find the problem.

Re: Memory Leak with ASCOM?
« Reply #12 on: April 12, 2021, 12:11:15 AM »
Based on what I am seeing, it looks like the ImageArray is not being released/freed when the camera object is disposed.

Re: Memory Leak with ASCOM?
« Reply #13 on: April 12, 2021, 04:40:52 AM »
Hi,
    I tried add ImgData = null and GC.collect() when disconnect,but it seem has no help,this way can't release the memory?
Best Regards,
QinXiaoXu

Re: Memory Leak with ASCOM?
« Reply #14 on: April 12, 2021, 06:44:06 AM »
I have trying within the program, but ImageArray is readonly and cannot set to null and GC.Collect() does not help with 21.03.13.17. Once again, version 20.08.26.19 worked fine. It might be valuable to compare...