googlevr / gvr-ios-sdk

Google VR SDK for iOS
http://developers.google.com/vr/ios/
Other
647 stars 191 forks source link

GVRVideoView memory leak #123

Closed subbotkin closed 8 years ago

subbotkin commented 8 years ago

I found that AVPlayer probably not releases added periodic time observers that causes memory leak both iOS9 and iOS10 devices.

2016-09-15 5 40 35 pm

I found this by creating a AVPlayer category that replaces addPeriodicTimeObserverForInterval:queue:usingBlock: with empty implementation and memory leak disappears.

@implementation AVPlayer (TimeObserver)

+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        SEL originalAddObserverSelector = @selector(addPeriodicTimeObserverForInterval:queue:usingBlock:);
        SEL swizzledAddObserverSelector = @selector(swizzled_addPeriodicTimeObserverForInterval:queue:usingBlock:);
        Method originalAddObserverMethod = class_getInstanceMethod(class, originalAddObserverSelector);
        Method swizzledAddObserverMethod = class_getInstanceMethod(class, swizzledAddObserverSelector);
        method_exchangeImplementations(originalAddObserverMethod, swizzledAddObserverMethod);
    });
}

- (id)swizzled_addPeriodicTimeObserverForInterval:(CMTime)interval queue:(nullable dispatch_queue_t)queue usingBlock:(void (^)(CMTime time))block
{
    return nil;
}

@end

So removing added periodic time observers before dealloc AVPlayer may help.

sanjayc77 commented 8 years ago

This was fixed in the GVRSDK 1.0 release. Please verify and re-open if not.