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,11 +44,11 @@ void __quit_on_exception( void * e, const char * function, const char * file, in ...@@ -44,11 +44,11 @@ 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;
return nil; return 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,38 +90,30 @@ static void *DestroySharedLibraryAtExit() ...@@ -93,38 +90,30 @@ 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 if (instance)
// following code allows for the framework to be removed without crashing
// the host application.
@try
{
if (instance)
{
libvlc_exception_t ex;
libvlc_exception_init( &ex );
libvlc_destroy( instance, &ex );
}
}
@finally
{ {
instance = nil; libvlc_exception_t ex;
[audio release]; libvlc_exception_init( &ex );
[super dealloc];
libvlc_destroy( instance, &ex );
} }
instance = nil;
[audio release];
[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