Commit 0e514bd7 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/VLCLibrary.m: Better memory management for the global...

MacOSX/Framework/VLCLibrary.m: Better memory management for the global VLCLibrary object. Give an autoreleased object in +[VLCLibrary sharedLibrary]. Release the global VLCLibrary atexit.
parent 87bc7007
...@@ -44,8 +44,8 @@ void __quit_on_exception( void * e, const char * function, const char * file, in ...@@ -44,8 +44,8 @@ void __quit_on_exception( void * e, const char * function, const char * file, in
static void *DestroySharedLibraryAtExit() static void *DestroySharedLibraryAtExit()
{ {
// Destroy the shared library /* Release the global object that may have been alloc-ed
if (sharedLibrary) * in -[VLCLibrary init] */
[sharedLibrary release]; [sharedLibrary release];
sharedLibrary = nil; sharedLibrary = nil;
...@@ -59,11 +59,8 @@ static void *DestroySharedLibraryAtExit() ...@@ -59,11 +59,8 @@ static void *DestroySharedLibraryAtExit()
{ {
// Initialize a shared instance // Initialize a shared instance
[[self alloc] init]; [[self alloc] init];
// Register a function to gracefully destroy the shared library on exit.
atexit( (void*)DestroySharedLibraryAtExit );
} }
return sharedLibrary; return [[sharedLibrary retain] autorelease];
} }
+ (void *)sharedInstance + (void *)sharedInstance
...@@ -93,24 +90,20 @@ static void *DestroySharedLibraryAtExit() ...@@ -93,24 +90,20 @@ static void *DestroySharedLibraryAtExit()
quit_on_exception( &ex ); quit_on_exception( &ex );
if (!sharedLibrary) if (!sharedLibrary)
sharedLibrary = [[self retain] autorelease]; sharedLibrary = self;
// Assignment unneeded, as the audio unit will do it for us // Assignment unneeded, as the audio unit will do it for us
/*audio = */ [[VLCAudio alloc] initWithLibrary:self]; /*audio = */ [[VLCAudio alloc] initWithLibrary:self];
// free allocated resources // free allocated resources
free( applicationPath ); free( applicationPath );
atexit(DestroySharedLibraryAtExit);
} }
return self; return self;
} }
- (void)dealloc - (void)dealloc
{ {
// TODO: libvlc core locks up or has segfaults while shutting down, the
// following code allows for the framework to be removed without crashing
// the host application.
@try
{
if (instance) if (instance)
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
...@@ -118,13 +111,9 @@ static void *DestroySharedLibraryAtExit() ...@@ -118,13 +111,9 @@ static void *DestroySharedLibraryAtExit()
libvlc_destroy( instance, &ex ); libvlc_destroy( instance, &ex );
} }
}
@finally
{
instance = nil; instance = nil;
[audio release]; [audio release];
[super dealloc]; [super dealloc];
}
} }
- (void *)instance - (void *)instance
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment