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

Memory leak occurs when linking against the Objective-C runtime. #75

Closed
marpaia opened this issue Aug 28, 2014 · 5 comments
Closed

Memory leak occurs when linking against the Objective-C runtime. #75

marpaia opened this issue Aug 28, 2014 · 5 comments

Comments

@marpaia
Copy link
Contributor

marpaia commented Aug 28, 2014

Given code that (literally) just links against osquery, here are some interesting valgrind results:

With neither RocksDB or Obj-C:

==62958== LEAK SUMMARY:
==62958==    definitely lost: 0 bytes in 0 blocks
==62958==    indirectly lost: 0 bytes in 0 blocks
==62958==      possibly lost: 0 bytes in 0 blocks
==62958==    still reachable: 4,096 bytes in 1 blocks
==62958==         suppressed: 25,768 bytes in 377 blocks

With RocksDB:

==69688== LEAK SUMMARY:
==69688==    definitely lost: 0 bytes in 0 blocks
==69688==    indirectly lost: 6,240 bytes in 6 blocks
==69688==      possibly lost: 0 bytes in 0 blocks
==69688==    still reachable: 6,992 bytes in 188 blocks
==69688==         suppressed: 26,768 bytes in 371 blocks

With RocksDB and Obj-C:

==64333== LEAK SUMMARY:
==64333==    definitely lost: 1,656 bytes in 35 blocks
==64333==    indirectly lost: 7,376 bytes in 10 blocks
==64333==      possibly lost: 2,576 bytes in 53 blocks
==64333==    still reachable: 111,364 bytes in 750 blocks
==64333==         suppressed: 193,892 bytes in 464 blocks
@marpaia
Copy link
Contributor Author

marpaia commented Aug 28, 2014

This might be because of some ARC shenanigans where the runtime expects ARC to exist, but it's not working as expected?

@marpaia
Copy link
Contributor Author

marpaia commented Aug 28, 2014

Keep in mind that 7376 - 6240 = 1136, so (also doing the other math) one might infer that Objective-C's impact alone (ie: without RocksDB) would be something like:

==64333== LEAK SUMMARY:
==64333==    definitely lost: 1,656 bytes in 35 blocks
==64333==    indirectly lost: 7,376 bytes in 10 blocks
==64333==      possibly lost: 2,576 bytes in 53 blocks
==64333==    still reachable: 104,372 bytes in 562 blocks
==64333==         suppressed: 167124 bytes in 464 blocks

@marpaia
Copy link
Contributor Author

marpaia commented Aug 28, 2014

Flags used to link against Objective-C: -fobjc-arc -fobjc-link-runtime -framework Foundation -framework IOKit -framework CoreFoundation -framework Security

@marpaia
Copy link
Contributor Author

marpaia commented Aug 28, 2014

I think that this is because, when I compile the Objective-C and C++ code, I'm compiling it all as C++. In order for my usage of Foundation to be managed by arc, I need to compile the .mm files as Objective-C (which allows for C++ interop) and link the compiled objects against the compiled C++ objects. The solution to this problem, if my guess is correct, will probably mostly be in CMake.

@marpaia
Copy link
Contributor Author

marpaia commented Aug 30, 2014

Fixed in 0e806ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant