Преглед на файлове

VLCLibrary: take stricter care of our shared library instance

Felix Paul Kühne преди 12 години
родител
ревизия
9032a525ed
променени са 2 файла, в които са добавени 15 реда и са изтрити 6 реда
  1. 0 3
      Headers/Public/VLCLibrary.h
  2. 15 3
      Sources/VLCLibrary.m

+ 0 - 3
Headers/Public/VLCLibrary.h

@@ -39,9 +39,6 @@
  * instiantiation of VLCLibrary, as previously noted, this is done automatically by the dynamic link loader.
  */
 @interface VLCLibrary : NSObject
-{
-    void * instance;
-}
 
 /* Factories */
 /**

+ 15 - 3
Sources/VLCLibrary.m

@@ -37,6 +37,14 @@
 #include <vlc/libvlc_structures.h>
 
 static VLCLibrary * sharedLibrary = nil;
+static void * sharedInstance = nil;
+
+@interface VLCLibrary()
+{
+    void *instance;
+}
+
+@end
 
 @implementation VLCLibrary
 + (VLCLibrary *)sharedLibrary
@@ -44,6 +52,7 @@ static VLCLibrary * sharedLibrary = nil;
     if (!sharedLibrary) {
         /* Initialize a shared instance */
         sharedLibrary = [[self alloc] init];
+        sharedInstance = sharedLibrary.instance;
     }
     return sharedLibrary;
 }
@@ -166,8 +175,11 @@ static VLCLibrary * sharedLibrary = nil;
     if (instance)
         libvlc_release(instance);
 
-    if (self == sharedLibrary)
+    if (self == sharedLibrary) {
         sharedLibrary = nil;
+        libvlc_release(sharedInstance);
+        sharedInstance = nil;
+    }
 
     [super dealloc];
 }
@@ -177,9 +189,9 @@ static VLCLibrary * sharedLibrary = nil;
 @implementation VLCLibrary (VLCLibVLCBridging)
 + (void *)sharedInstance
 {
-    NSAssert([self sharedLibrary].instance, @"shared library doesn't have an instance");
+    NSAssert(sharedInstance, @"shared library doesn't have an instance");
 
-    return [self sharedLibrary].instance;
+    return sharedInstance;
 }
 
 - (void *)instance