Topic locked

Serious memory leak in native iOS demo

July 27, 2021 - 8:39pm #3

Hello Vuforia people --

We're working based on the native iOS demo with SDK 9.8.5 and the corresponding sample project, and have run up against a very bad memory leak related to Vuforia rendering with Metal.

After a bit of investigating, we found that the issue is also present in the sample app.  On an iPhone X test device running iOS 14.6, the app's memory use increases by over 3 MB per second.  The sample app crashes within a few minutes of opening the Vuforia window in image tracking mode.

A bit of work with the Xcode memory graph debugger led me to this bit in VuforiaView.swift:

 

if (prepareToRender(&viewportsValue, 
                    UnsafeMutableRawPointer(Unmanaged.passRetained(mMetalDevice!).toOpaque()),
                    UnsafeMutableRawPointer(Unmanaged.passRetained(drawable!.texture).toOpaque()),
                    UnsafeMutableRawPointer(Unmanaged.passRetained(encoder!).toOpaque()))) {
...
}

 

// Pass Metal context data to Vuforia Engine (we may have changed the encoder since
// calling Vuforia::Renderer::begin)
finishRender(UnsafeMutableRawPointer(Unmanaged.passRetained(drawable!.texture).toOpaque()), 
             UnsafeMutableRawPointer(Unmanaged.passRetained(encoder!).toOpaque()))

The passUnretained pointers seem to be the cause. Switching them to passUnretained seems to resolve the leak issue, but I'm concerned that will lead to memory corruption, and obviously the code was written with the passUnretained for a reason. My hope is that someone from Vuforia can shed some light on this, and tighten up the sample project in general. Thanks!

Serious memory leak in native iOS demo

July 28, 2021 - 11:35am #2

Hello,

Thank you for the investigation and report. I know we have been tracking some memory leaks, but unclear if it is related to your report.

I will escalate to the team for additional investigation.

Thanks,

Vuforia Engine Support

Serious memory leak in native iOS demo

July 29, 2021 - 9:15am #1

Hello @LocalProjects,

The team has confirmed that you are correct: calls to passRetained should be replaced with passUnretained. Additionally, as part of our Engine 10.0 release, we fixed another significant memory leak when changing between experiences.

With the 10.0 release now available, which includes a significant refactoring (and simplification) of our APIs, would you consider targeting that release for your development? We will continue to patch our final legacy release, 9.8.X, but it is unclear if we would patch our native samples considering their low usage rate. There will be considerably more momentum for patching issues found in our 10.X SDK and samples, where we will look restart a frequent release cadence.

Thanks,

Vuforia Engine Support

Topic locked