Comments (11)
Hi Thordin, thanks for the report. Did you call camera.stop()
upon exit?
from dxcam.
No I did not but I think it would call the __del__
method on that class upon exit right? The only time I closed the script was by pressing ctrl+c or if an exception was thrown.
I just realized I did not check the commit usage so this might be a false positive. I will continue running the script for a few days with the same settings and double check to make sure it isn't another program eating up the ram. But it would be strange if something was occupying so much commit, there shouldn't have been 6 gb physical free.
from dxcam.
I think I figured out the issue or at least 1 source of a leak.
I put a print statement in __del__
here.
Line 242 in cd1c367
It gets called if you don't use capture. However if you use capture, it will not get printed if the program quits.
I believe it is because the thread holds open a reference to the object so the object never gets garbage collected and never calls __del__
, even if the thread is set to daemon.
from dxcam.
__del__
will have a similar logic, but __del__
on python can't be always trusted.(e.g. https://stackoverflow.com/a/6104568 and python gc documentation) So I would recommend calling .stop
/.release
explicitly to make sure everything is cleaned up. There are certainly more user-friendly ways to do the clean up and I will make improvement probably in next version.
As for the leak, I haven't tested it for running for days, but when I ran it for ~ an hour it maintains a constant memory footprint and cleaned up upon exit. I will double-check when I'm back from traveling.
from dxcam.
Not sure why this happens but this short little script causes an error when I release it.
import dxcam
import time
dx = dxcam.create()
dx.start()
time.sleep(2)
f = dx.get_latest_frame()
dx.release()
python test2.py
Screen Capture FPS: 54
Exception ignored in: <function _compointer_base.__del__ at 0x000001B21D44DA20>
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\comtypes\__init__.py", line 957, in __del__
self.Release()
File "C:\Python310\lib\site-packages\comtypes\__init__.py", line 1212, in Release
return self.__com_Release()
OSError: exception: access violation writing 0x0000000000000000
from dxcam.
Try call .stop
before .release
:
import dxcam
import time
dx = dxcam.create()
dx.start()
time.sleep(2)
f = dx.get_latest_frame()
dx.stop()
dx.release()
Normally you don't need to call .release
since the logic is handled in the destructor. But in the case of having memory issues, it's better to do it explicitly I guess.
from dxcam.
Try call
.stop
before.release
:import dxcam import time dx = dxcam.create() dx.start() time.sleep(2) f = dx.get_latest_frame() dx.stop() dx.release()
Normally you don't need to call
.release
since the logic is handled in the destructor. But in the case of having memory issues, it's better to do it explicitly I guess.
According to the code, release calls stop as the first thing it does though.
Line 237 in cd1c367
from dxcam.
Just confirmed the memory leak. It happened again.
I tried connecting to the computer with remote desktop (parsec) it threw an error complaining about the video encoder not working. So I went to the machine physically, stopped the script, then found out it wouldn't start again.
self.d3dshot = dxcam.create(max_buffer_len=2)
File "C:\Python310\lib\site-packages\dxcam\__init__.py", line 110, in create
return __factory.create(
File "C:\Python310\lib\site-packages\dxcam\__init__.py", line 70, in create
camera = DXCamera(
File "C:\Python310\lib\site-packages\dxcam\dxcam.py", line 30, in __init__
self._stagesurf: StageSurface = StageSurface(
File "<string>", line 8, in __init__
File "C:\Python310\lib\site-packages\dxcam\core\stagesurf.py", line 20, in __post_init__
self.rebuild(output, device)
File "C:\Python310\lib\site-packages\dxcam\core\stagesurf.py", line 44, in rebuild
device.device.CreateTexture2D(
_ctypes.COMError: (-2147024882, 'Not enough memory resources are available to complete this operation.', (None, None, None, 0, None))
I checked task manager and physical ram/commit were under the limits. GPU ram however was stuck at 1.9/2.0 ghz with everything closed. Logging off the account was enough to release the memory.
So I think this is proof that some gpu memory is leaking, and not just an issue when exiting the script. dx.release() was already added before this run.
from dxcam.
Hi Thordin, thanks for the reply. Seems there's a memory leak somewhere. I'm trying to figure out the issue: Does your script /workflow involve multiple re-initializations? E.g. re-create of dxcam instance, output mode change, etc?
Possibly related:
https://forums.developer.nvidia.com/t/dxgi-outputduplication-memory-leak-when-using-nv-but-not-amd-drivers/108582
from dxcam.
Hello I have been editing and re-running my script multiple times.
I withdraw my claim about a memory leak from just leaving it running, there's maybe just the one caused by the release issue I mentioned above.
I increased my page file and it doesn't run out of memory after several days anymore.
from dxcam.
Cool. Good to know. Please let me know if there are any other issues.
from dxcam.
Related Issues (20)
- OSError: [WinError 87] error
- AttributeError: 'DXCamera' object has no attribute 'is_capturing' HOT 1
- TypeError: 'float' object cannot be interpreted as an integer
- PyPI 站没有了
- Capturing on HDR display has very bright output HOT 1
- Helllo win 7 doesn't work
- feedback BUG:camera.grab() Resolution error
- feedback BUG:camera.grab() Resolution error HOT 5
- [NOT-ISSUE] [TUTORIAL] Adding Cursor To Screen Capture HOT 1
- Is there any way to have the captured screenshots include the mouse cursor? HOT 1
- All frames taken from camera.get_latest_frame() are glitchy in a weird way!
- ValueError: could not broadcast input array from shape (640,640,3) into shape (1080,1920,3)
- How can I take screenshots based on the specified hwnd
- Capturing a screen screenshot of a virtual desktop in Windows 10
- Dxcam has no attribute 'create'
- Dxcam can't find gpu?
- access violation writing 0x4DBAF26F
- DXCAM does not respond
- numpy processor
- Please give an option to not return None if theres a duplicate. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dxcam.