Fixed bug 1641 - avoid allocating nsstring from char*
Vittorio Giovara 2012-11-12 05:52:47 PST Changesets 4f272256d172 and 42214b6959c5 introduce two neat features for logging and alertbox on ios and osx. However the NSString allocated (and a few other objects) are not freed by the autorelease pool when created by +alloc and -initWithStuff: and this will create leaks. While negligible on osx, on mobile it's better not to have leaks. Attached is a patch that should take care of the problems on both platforms.
This commit is contained in:
parent
7daed4ab7b
commit
8042e18f9a
4 changed files with 10 additions and 14 deletions
|
@ -51,8 +51,8 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
[alert setAlertStyle:NSInformationalAlertStyle];
|
||||
}
|
||||
|
||||
[alert setMessageText:[[NSString alloc] initWithUTF8String:messageboxdata->title]];
|
||||
[alert setInformativeText:[[NSString alloc] initWithUTF8String:messageboxdata->message]];
|
||||
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
|
||||
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
|
||||
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
int i;
|
||||
|
@ -70,6 +70,7 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
NSInteger clicked = [alert runModal];
|
||||
clicked -= NSAlertFirstButtonReturn;
|
||||
*buttonid = buttons[clicked].buttonid;
|
||||
[alert release];
|
||||
|
||||
[pool release];
|
||||
|
||||
|
|
|
@ -228,11 +228,7 @@ Cocoa_CreateImage(SDL_Surface * surface)
|
|||
|
||||
void SDL_NSLog(const char *text)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
|
||||
|
||||
[pool release];
|
||||
NSLog(@"%s", text);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -76,8 +76,8 @@ UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
|
||||
UIAlertView* alert = [[UIAlertView alloc] init];
|
||||
|
||||
alert.title = [[NSString alloc] initWithUTF8String:messageboxdata->title];
|
||||
alert.message = [[NSString alloc] initWithUTF8String:messageboxdata->message];
|
||||
alert.title = [NSString stringWithUTF8String:messageboxdata->title];
|
||||
alert.message = [NSString stringWithUTF8String:messageboxdata->message];
|
||||
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
|
||||
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
|
@ -100,6 +100,9 @@ UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
s_showingMessageBox = SDL_FALSE;
|
||||
|
||||
*buttonid = messageboxdata->buttons[clicked].buttonid;
|
||||
|
||||
[alert.delegate release];
|
||||
[alert release];
|
||||
|
||||
[pool release];
|
||||
|
||||
|
|
|
@ -137,11 +137,7 @@ UIKit_VideoQuit(_THIS)
|
|||
|
||||
void SDL_NSLog(const char *text)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
|
||||
|
||||
[pool release];
|
||||
NSLog(@"%s", text);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue