-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Finding out memory usage in C++ #8082
Comments
You can find the current size of the heap from any of the views, There is also the |
If you want current memory usage (not just total heap size), |
I think that --memoryprofiler does not count "DYNAMIC memory area used" properly in case of multithreaded system (just shows main thread allocs). Also sbrk seems to be not useful since show similar thing like "DYNAMIC memory area size" so summarized memory allocated also by other threads than main but never updates whilst free/delete is called. Additionally --memoryprofiler cost some performance. Luckily there is relatively simple workaround (but at the cost of memory overhead with small impact on performance). Just override new/malloc/free/delete with your own implementation:
|
Do not forget to override |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
We have a pretty big app running using Emscripten that has to handle some pretty big PDF files sometimes. We try to cache as much data as possible, to make runtime performance as good as possible. On iOS and Android, we use the OS memory notifications to reduce memory as needed.
I haven't found a way yet in WASM/asmjs to do something similar. I understand there aren't any memory notifications, but, for example, is there a way to get the size of the heap when
ALLOW_MEMORY_GROWTH
is defined?Basically, any information that I can query at runtime to see how much memory is used or available would be extremely beneficial. Our application is unfortunately not designed to behave correctly when malloc fails (due to so many operating systems simply overcommiting anyway), so we're running into OOM situations quite often.
BTW, thanks for all the work on it, it's been working really great so far!
The text was updated successfully, but these errors were encountered: