ARVideoKit icon indicating copy to clipboard operation
ARVideoKit copied to clipboard

Potential Memory Leak

Open mssjappjwt opened this issue 8 years ago • 10 comments

First of all, thank you for sharing this framework!

I've been getting errors when the app goes into background: Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)

I suspect the RecordAR is never been dealloc, maybe because RecordAR holds a strong reference to ARSceneKit which might potentially create a retain cycle in certain cases?

Thank you

mssjappjwt avatar Mar 13 '18 00:03 mssjappjwt

Will investigate the issue and get back to you soon.

AFathi avatar Mar 13 '18 04:03 AFathi

Thank you!

To give you a little more context, in my case I have a button that can switch between AR camera and normal camera. So if you choose to programmatically initialize and add ARSCNView to the view hierarchy based on certain action. You'll have UIViewController holding a strong reference to ARSCNView, UIViewController holding a strong reference to RecordAR and RecordAR holding a strong reference to ARSCNView. And I saw in your source code RecordAR also holds a strong reference to ARSCNView's parent view controller which might cause a retain cycle (Didn't look too deep into the source code, I think this is the case).

mssjappjwt avatar Mar 13 '18 06:03 mssjappjwt

facing the same issue. RecordAR holding strong reference to the ARSCNView.

devajith avatar Jul 19 '18 06:07 devajith

@mssjappjwt did you find any workaround for this like passing unowned or weak ARSCNView ?

devajith avatar Jul 19 '18 06:07 devajith

how to fix

tulaomaod avatar Aug 10 '18 03:08 tulaomaod

Facing same issue, app crashing..

anilios avatar Oct 25 '18 06:10 anilios

Facing same issue, app crashing..

tulaomaod avatar Dec 15 '18 09:12 tulaomaod

Taking a global strong reference to view object is a bad idea:

import Foundation
import ARKit

private var view: Any? // this must be instance & weak variable!
private var renderEngine: SCNRenderer! // instance variable too 

@available(iOS 11.0, *)
struct RenderAR {
    var ARcontentMode: ARFrameMode!
    .....

https://github.com/AFathi/ARVideoKit/blob/c51fc0db850b8106babba2bd9105974b348b0c3e/ARVideoKit/Rendering/RenderAR.swift#L12

... and other classes.

dneprDroid avatar Jan 14 '19 15:01 dneprDroid

@dneprDroid

Feel free to submit a pull request with the fixes.

AFathi avatar Jan 14 '19 15:01 AFathi

I have checked it, and with these changes component is deallocated. https://github.com/AFathi/ARVideoKit/pull/82

asam139 avatar May 01 '19 14:05 asam139