Skip to content
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

[Build] memory leaked #23915

Open
zxj329 opened this issue Mar 6, 2025 · 5 comments
Open

[Build] memory leaked #23915

zxj329 opened this issue Mar 6, 2025 · 5 comments
Labels
build build issues; typically submitted using template platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@zxj329
Copy link

zxj329 commented Mar 6, 2025

Describe the issue

i use valgrind to check memory leak
valgrind --log-file=vg.log --track-origins=yes --leak-check=full --show-leak-kinds=all --read-var-info=yes ./df_onnx_runtime_ort_linux ./ ./test.wav ./audio_linux.wav
the log is :
HEAP SUMMARY:
==96628== in use at exit: 18,960 bytes in 12 blocks
==96628== total heap usage: 3,156,447 allocs, 3,156,435 frees, 316,270,850 bytes allocated
==96628==
==96628== 16 bytes in 1 blocks are still reachable in loss record 1 of 12
==96628== at 0x4C3217F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F75726: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 64 bytes in 1 blocks are still reachable in loss record 2 of 12
==96628== at 0x4C3217F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F755F3: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x1F: ???
==96628== by 0x51A9DBF: ???
==96628== by 0x3: ???
==96628== by 0x4F757DB: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 256 bytes in 1 blocks are still reachable in loss record 3 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AEE8: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 288 bytes in 1 blocks are still reachable in loss record 4 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7ADCB: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 448 bytes in 1 blocks are still reachable in loss record 5 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AD7D: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 832 bytes in 1 blocks are still reachable in loss record 6 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AC82: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 832 bytes in 1 blocks are still reachable in loss record 7 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7ACE8: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 1,664 bytes in 1 blocks are still reachable in loss record 8 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AE17: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 1,664 bytes in 1 blocks are still reachable in loss record 9 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AE60: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 1,664 bytes in 1 blocks are still reachable in loss record 10 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AEA6: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 2,912 bytes in 1 blocks are still reachable in loss record 11 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7AD29: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== 8,320 bytes in 1 blocks are still reachable in loss record 12 of 12
==96628== at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==96628== by 0x4F7A94E: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x5E16906: __pthread_once_slow (pthread_once.c:116)
==96628== by 0x4F7A532: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628== by 0x4F626EA: ??? (in /home/zhengxinjiang/code/DeepFilterNet-main/deepfilternet3_CPP/onnxruntime/lib/libonnxruntime.so.1)
==96628==
==96628== LEAK SUMMARY:
==96628== definitely lost: 0 bytes in 0 blocks
==96628== indirectly lost: 0 bytes in 0 blocks
==96628== possibly lost: 0 bytes in 0 blocks
==96628== still reachable: 18,960 bytes in 12 blocks
==96628== suppressed: 0 bytes in 0 blocks
==96628==
==96628== For counts of detected and suppressed errors, rerun with: -v
==96628== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Urgency

No response

Target platform

ubuntu18.04

Build script

python3 ./tools/ci_build/build.py
--build_dir ./build-ios/arm64
--skip_submodule_sync
--config=MinSizeRel
--minimal_build
--include_ops_by_config=required_operators_ORT.config
--use_xcode
--cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF
--cmake_extra_defines onnxruntime_BUILD_SHARED_LIB=OFF
--ios
--apple_sysroot iphoneos
--osx_arch arm64
--parallel
--skip_tests
--build_apple_framework
--apple_deploy_target '13.0'
--compile_no_warning_as_error

Error / output

i found memory leak occur in libonnxruntime.so

Visual Studio Version

No response

GCC / Compiler Version

No response

@zxj329 zxj329 added the build build issues; typically submitted using template label Mar 6, 2025
@github-actions github-actions bot added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Mar 6, 2025
@skottmckay
Copy link
Contributor

Most like this applies: #23798 (comment)

There are some statics in 3rd party libraries like protobuf and cpuinfo that we can't free.

@zxj329
Copy link
Author

zxj329 commented Mar 6, 2025

Most like this applies: #23798 (comment)

There are some statics in 3rd party libraries like protobuf and cpuinfo that we can't free.
my libonnxruntime.so do not use protobuf。because in my build.sh, i use --minimal_building

@zxj329
Copy link
Author

zxj329 commented Mar 6, 2025

Most like this applies: #23798 (comment)

There are some statics in 3rd party libraries like protobuf and cpuinfo that we can't free.
i define some static variable in cpp file。like that:
static vector input_tensors;
static Env env;

static Session *session = nullptr;
static SessionOptions sessionOptions = SessionOptions();

and in free function, i just delete session.can u tell me whether it is neceaasry to free env?

@skottmckay
Copy link
Contributor

Typically one would free the Ort::Env, but only once all usage of ORT has completed. You own the instance of that that you create.

@zxj329
Copy link
Author

zxj329 commented Mar 11, 2025

Typically one would free the Ort::Env, but only once all usage of ORT has completed. You own the instance of that that you create.
so how to solve memory leaked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build issues; typically submitted using template platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants