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 setAlertStyle:NSInformationalAlertStyle];
|
||||||
}
|
}
|
||||||
|
|
||||||
[alert setMessageText:[[NSString alloc] initWithUTF8String:messageboxdata->title]];
|
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
|
||||||
[alert setInformativeText:[[NSString alloc] initWithUTF8String:messageboxdata->message]];
|
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
|
||||||
|
|
||||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||||
int i;
|
int i;
|
||||||
|
@ -70,6 +70,7 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||||
NSInteger clicked = [alert runModal];
|
NSInteger clicked = [alert runModal];
|
||||||
clicked -= NSAlertFirstButtonReturn;
|
clicked -= NSAlertFirstButtonReturn;
|
||||||
*buttonid = buttons[clicked].buttonid;
|
*buttonid = buttons[clicked].buttonid;
|
||||||
|
[alert release];
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
|
|
|
@ -228,11 +228,7 @@ Cocoa_CreateImage(SDL_Surface * surface)
|
||||||
|
|
||||||
void SDL_NSLog(const char *text)
|
void SDL_NSLog(const char *text)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSLog(@"%s", text);
|
||||||
|
|
||||||
NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
|
|
||||||
|
|
||||||
[pool release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -76,8 +76,8 @@ UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||||
|
|
||||||
UIAlertView* alert = [[UIAlertView alloc] init];
|
UIAlertView* alert = [[UIAlertView alloc] init];
|
||||||
|
|
||||||
alert.title = [[NSString alloc] initWithUTF8String:messageboxdata->title];
|
alert.title = [NSString stringWithUTF8String:messageboxdata->title];
|
||||||
alert.message = [[NSString alloc] initWithUTF8String:messageboxdata->message];
|
alert.message = [NSString stringWithUTF8String:messageboxdata->message];
|
||||||
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
|
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
|
||||||
|
|
||||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||||
|
@ -101,6 +101,9 @@ UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||||
|
|
||||||
*buttonid = messageboxdata->buttons[clicked].buttonid;
|
*buttonid = messageboxdata->buttons[clicked].buttonid;
|
||||||
|
|
||||||
|
[alert.delegate release];
|
||||||
|
[alert release];
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -137,11 +137,7 @@ UIKit_VideoQuit(_THIS)
|
||||||
|
|
||||||
void SDL_NSLog(const char *text)
|
void SDL_NSLog(const char *text)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSLog(@"%s", text);
|
||||||
|
|
||||||
NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
|
|
||||||
|
|
||||||
[pool release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue