-
-
Notifications
You must be signed in to change notification settings - Fork 844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory leak when accessing a.b. a is a Python instance & PyProxy in JS, b is either np.ndarray/bytes and is PyProxyBuffer in JS #1853
Comments
|
Could you post a minimal code example demonstrating the bug? It's a little bit hard to make a reproduction from the information you gave. |
|
Oh okay I understand why the |
|
Are you sure the symptoms of |
|
Also, thanks for the report @grimmer0125! This is very useful. |
Yes, I'm sure the symptoms of
|
Could you give a minimized code example for this? It is hard to diagnose based on the description in words. Also, what are you using to measure whether a leak occurred? Can you try running the same code on the development version? Does your code function in the same way there? Does the leak happen in the same way? I think #1573 might have changed the behavior a bit. |
|
I'll find time to prepare a minimized code example for this. Indeed it is a little complicated case. I use macOS built-in activity monitor to see the memory leak. A couple of minutes ago, I used https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.js to test and the results are the same, either |
|
Thanks for checking.
I am not sure whether that will be an accurate measure. It is possible that you allocate
Yes.
Yes, unless certain CI steps fail on main branch. |
I agree. It is not accurate since we need to read it with human eyes. allocate means? When I prepare the minimized code example, I am aware that the prevoius test result is incorrect. When I tested |
|
In that case I think #1854 fixes your problem. Once we merge it, you can try again using the updated development build and hopefully it will work. Of course if you are willing to build the #1854 branch yourself, you can try it out now. Thanks again for your helpful feedback.
Haha, very true.
Oops I started a sentence and forgot to finish it, should have read over my comment before posting. |
I may wait for merging #1854. I ever built the pyodide on my old macbook pro but now I use mac M1 and the docker image seems not built for arm64/universal. I got a few more questions when I refactor my current code, and they might not be related to this issue. 1.I have a JS decoder function, its parameter is // called in Python for decoding medical files for 1st rendering. pass Python bytes object
function js_decoder(bytes: ArrayBuffer) {
// Actually it will be PyProxy for this case
// internal_decode needs a ArrayBuffer but passing PyProxy works !! No toJs/ getBuffer
const decoded = internal_decode(bytes) // jpeg lossless decoder function
}2.When repeating the above 1. case, the memory See #1853 (comment) update 3I've got a 1 time special exception as the below screenshots when repeating 1st case code (just direct pass |
|
20210926 update for the above the 2. issue in #1853 (comment): case1 (original code): case2: Since the new version // called in Python for decoding medical files for 1st rendering. pass Python bytes object
function js_decoder(bytes: ArrayBuffer) {
// Actually it will be PyProxy for this case
// original
// const decoded = internal_decode(bytes)
// new:
const newBuffer = bytes.getBuffer()
const decoded = internal_decode(buffer.data)
newBuffer.release() // without release, the newBuffer will definitely leak memory
...
..
} |
Could you please send a reproduction? We would like to fix this if possible. I am also not clear why it would work to pass |
I don't understand why this works either. Please share an illustrative code example? (If you have private logic, you can presumably remove it and just keep the memory reads / writes.) |
Yes, this is how you should do it. After merging #1573 (so on development branch), this won't leak even if you pass |
|
@grimmer0125 now that I merged this can you test your code again on the development version? If it still doesn't work as expected, please open new issue. |
|
@hoodmane I used the below to test, and the result is the same, memory usage becomes 2GB within 20s. Actually, my project is open-sourced,
Python caller part is https://github.com/grimmer0125/embedded-pydicom-react-viewer/blob/test_memory_leak_and_strange_decode_function_accept_pyproxy_work/python/dicom_parser.py#L196 To test them, just The testing files are
If they are too complicated (e.g. the source code is a mass), please tell me and I may find some time to make a simplified demo code. |
|
@grimmer0125 Are there remaining problems that occur on most recent main branch? If so, could you open a new issue clarifying what they are? I am having a hard time finding whether there are specific things to be addressed here. It's great that the code is open source, that will be helpful if there are further problems. |
How can I make sure whether the downloaded |





Test environment:
User scenario:
I'm trying to make a medical image viewer which needs frequent (10~30 fps) rerendering in some cases. I define a Python class and plan to reuse it on JS side, this idea is from #1426 and a part of the code of the flow is like the part in #1833 (reply in thread).
Python class (in an external Python file):
When the mouse button is pressed and a mouse move event is triggered, JS will
dicomObj.rerender(). dicomObj is a PyProxy.ndarray/bytesinternally are re-calculated and renewed tondarray_data/pixel_bytesattributes on Python side.The accessing result is
dicomObj.rgba_1d_ndarrayis accessed on JS. The memory leak is over 100 MB/s (fps is over 30fps), regardless I triedrgba_1d_ndarray.destroy()and commenting the followinggetBufferusage.@propertyto access Python internal ndarray_data but got the same memory leak.ndarraydata and the memory will not leak. UsedicomObj.get_ndarray_data()to access. On python:ndarray_data, this part is not very harmful.The text was updated successfully, but these errors were encountered: