The issue here is that we have a reference cycle of shared pointers, one from Joint to Link and another one from Link to Joint. This can cause orphaned cycles to be leaked.
The fix for this is to use a std::weak_ptr which I have done for the child_link_ and parent_link_ in the Joint class.
After the updates, I get the following memory leak report:
leaks --atExit -- ./testForwardKinematicsFactor
testForwardKinematicsFactor(8235) MallocStackLogging: could not tag MSL-related memory as no_footprint, so those pages will be included in process footprint - (null)
testForwardKinematicsFactor(8235) MallocStackLogging: recording malloc and VM allocation stacks using lite mode
There were no test failures
Process: testForwardKinematicsFactor [8235]
Path: /Users/USER/*/testForwardKinematicsFactor
Load Address: 0x100cb4000
Identifier: testForwardKinematicsFactor
Version: 0
Code Type: ARM64
Platform: macOS
Parent Process: leaks [8234]
Date/Time: 2024-10-22 09:58:38.896 -0400
Launch Time: 2024-10-22 09:58:38.086 -0400
OS Version: macOS 14.6.1 (23G93)
Report Version: 7
Analysis Tool: /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version: Xcode 16.0 (16A242d)
Physical footprint: 10.8M
Physical footprint (peak): 28.4M
Idle exit: untracked
----
leaks Report Version: 4.0, multi-line stacks
Process 8235: 250 nodes malloced for 39 KB
Process 8235: 0 leaks for 0 total leaked bytes.
I ran
leaks
on thetestForwardKinematics
executable and I got the following memory leak reported.The issue here is that we have a reference cycle of shared pointers, one from
Joint
toLink
and another one fromLink
toJoint
. This can cause orphaned cycles to be leaked.The fix for this is to use a
std::weak_ptr
which I have done for thechild_link_
andparent_link_
in theJoint
class.After the updates, I get the following memory leak report: