Skip to content
Browse files

Use @autoreleasepool blocks

  • Loading branch information...
1 parent 7d50b4d commit 983bce86aa4b005f39bde54da0d4952808d78e9e @sorbits sorbits committed
View
12 Applications/TextMate/src/AppController Documents.mm
@@ -203,13 +203,13 @@ - (BOOL)loadSession:(id)sender
- (void)closeAllWindows:(id)sender
{
D(DBF_AppController_Documents, bug("\n"););
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- for(NSWindow* window in [NSApp windows])
- {
- if(window.isVisible)
- [window close];
+ @autoreleasepool {
+ for(NSWindow* window in [NSApp windows])
+ {
+ if(window.isVisible)
+ [window close];
+ }
}
- [pool release];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
View
12 Applications/TextMate/src/main.mm
@@ -68,13 +68,13 @@ int main (int argc, char const* argv[])
pthread_detach(thread);
else perror("pthread_create()");
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- for(NSString* variable in [[[NSProcessInfo processInfo] environment] allKeys])
- {
- if([variable hasPrefix:@"TM_"])
- unsetenv([variable UTF8String]);
+ @autoreleasepool {
+ for(NSString* variable in [[[NSProcessInfo processInfo] environment] allKeys])
+ {
+ if([variable hasPrefix:@"TM_"])
+ unsetenv([variable UTF8String]);
+ }
}
- [pool release];
return NSApplicationMain(argc, argv);
}
View
10 Applications/decompile_as/src/decompile_as.mm
@@ -11,11 +11,11 @@ int main (int argc, char const* argv[])
return 0;
}
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- NSDictionary* errorInfo = nil;
- OSAScript* script = [[OSAScript alloc] initWithCompiledData:[[NSFileHandle fileHandleWithStandardInput] readDataToEndOfFile] error:&errorInfo];
- std::string str = [[script source] UTF8String];
- [pool drain];
+ @autoreleasepool {
+ NSDictionary* errorInfo = nil;
+ OSAScript* script = [[OSAScript alloc] initWithCompiledData:[[NSFileHandle fileHandleWithStandardInput] readDataToEndOfFile] error:&errorInfo];
+ std::string str = [[script source] UTF8String];
+ }
std::replace(str.begin(), str.end(), '\r', '\n');
write(STDOUT_FILENO, str.data(), str.size());
View
64 Frameworks/BundlesManager/src/BundlesManager.mm
@@ -65,40 +65,38 @@ - (void)didFinishActivityForSources:(std::vector<bundles_db::source_ptr> const&)
bool background_task_t::handle_request (request_t const& request)
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
-
- std::vector<bundles_db::source_ptr> const& sources = request.sources;
- std::vector<bundles_db::bundle_ptr> const& bundles = request.bundles;
- BundlesManager* self = request.bundles_manager;
-
- for(size_t i = 0; i < sources.size(); ++i)
- {
- self.threadProgress = i / (double)sources.size();
- self.threadActivityText = [NSString stringWithFormat:@"Updating ‘%s’…", sources[i]->name().c_str()];
- bundles_db::update(sources[i], request.thread_progress, i / (double)sources.size(), (i + 1) / (double)sources.size());
+ @autoreleasepool {
+ std::vector<bundles_db::source_ptr> const& sources = request.sources;
+ std::vector<bundles_db::bundle_ptr> const& bundles = request.bundles;
+ BundlesManager* self = request.bundles_manager;
+
+ for(size_t i = 0; i < sources.size(); ++i)
+ {
+ self.threadProgress = i / (double)sources.size();
+ self.threadActivityText = [NSString stringWithFormat:@"Updating ‘%s’…", sources[i]->name().c_str()];
+ bundles_db::update(sources[i], request.thread_progress, i / (double)sources.size(), (i + 1) / (double)sources.size());
+ }
+
+ double totalSize = 0;
+ iterate(bundle, bundles)
+ totalSize += (*bundle)->size();
+
+ for(size_t size = 0, i = 0; i < bundles.size(); ++i)
+ {
+ self.threadProgress = size / totalSize;
+ self.threadActivityText = [NSString stringWithFormat:@"%@Installing ‘%s’…", (bundles.size() > 1 ? [NSString stringWithFormat:@"%zu/%zu: ", i+1, bundles.size()] : @""), bundles[i]->name().c_str()];
+ bundles_db::update(bundles[i], kInstallDirectory, request.thread_progress, size / totalSize, (size + bundles[i]->size()) / totalSize);
+ size += bundles[i]->size();
+ }
+
+ self.threadProgress = 1;
+ if(bundles.size() == 0)
+ self.threadActivityText = @"";
+ else if(bundles.size() == 1)
+ self.threadActivityText = [NSString stringWithFormat:@"Installed ‘%s’.", bundles.back()->name().c_str()];
+ else
+ self.threadActivityText = [NSString stringWithFormat:@"Installed %zu bundles.", bundles.size()];
}
-
- double totalSize = 0;
- iterate(bundle, bundles)
- totalSize += (*bundle)->size();
-
- for(size_t size = 0, i = 0; i < bundles.size(); ++i)
- {
- self.threadProgress = size / totalSize;
- self.threadActivityText = [NSString stringWithFormat:@"%@Installing ‘%s’…", (bundles.size() > 1 ? [NSString stringWithFormat:@"%zu/%zu: ", i+1, bundles.size()] : @""), bundles[i]->name().c_str()];
- bundles_db::update(bundles[i], kInstallDirectory, request.thread_progress, size / totalSize, (size + bundles[i]->size()) / totalSize);
- size += bundles[i]->size();
- }
-
- self.threadProgress = 1;
- if(bundles.size() == 0)
- self.threadActivityText = @"";
- else if(bundles.size() == 1)
- self.threadActivityText = [NSString stringWithFormat:@"Installed ‘%s’.", bundles.back()->name().c_str()];
- else
- self.threadActivityText = [NSString stringWithFormat:@"Installed %zu bundles.", bundles.size()];
-
- [pool drain];
return true;
}
View
8 Frameworks/Find/src/Find.mm
@@ -102,10 +102,10 @@ - (void)applicationWillTerminate:(NSNotification*)notification
// An autorelease pool is required here because the default pool will not be destroyed before termination,
// so objects cleaned up here would not be properly destroyed, and would report as leaking.
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- [windowController invalidate];
- self.windowController = nil;
- [pool drain];
+ @autoreleasepool {
+ [windowController invalidate];
+ self.windowController = nil;
+ }
}
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
View
6 Frameworks/OakAppKit/tests/t_dictionary.mm
@@ -139,8 +139,8 @@ - (NSArray*)validAttributesForMarkedText
public:
void test_dictionary ()
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- OakSetupApplicationWithView([[[MyTextView alloc] initWithFrame:NSMakeRect(0, 0, 400, 60)] autorelease], "dictionary");
- [pool drain];
+ @autoreleasepool {
+ OakSetupApplicationWithView([[[MyTextView alloc] initWithFrame:NSMakeRect(0, 0, 400, 60)] autorelease], "dictionary");
+ }
}
};
View
6 Frameworks/OakDebug/src/OakAssert.mm
@@ -106,9 +106,9 @@ void OakPrintBadAssertion (char const* lhs, char const* op, char const* rhs, std
@implementation OakExceptionHandlerDelegate
+ (void)load
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableAllExceptions:) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
- [pool release];
+ @autoreleasepool {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableAllExceptions:) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
+ }
}
+ (void)enableAllExceptions:(NSNotification*)aNotification
View
14 Frameworks/OakDebug/src/OakDebugMenu.mm
@@ -52,15 +52,15 @@
@implementation OakDebugMenu
+ (void)load
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(installDebugMenu:) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
+ @autoreleasepool {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(installDebugMenu:) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
- if(NSArray* debugEnabled = [[NSUserDefaults standardUserDefaults] objectForKey:@"OakDebug Enabled"])
- {
- for(NSString* flag in debugEnabled)
- OakDebugBaseClass::registry()[[flag UTF8String]] = true;
+ if(NSArray* debugEnabled = [[NSUserDefaults standardUserDefaults] objectForKey:@"OakDebug Enabled"])
+ {
+ for(NSString* flag in debugEnabled)
+ OakDebugBaseClass::registry()[[flag UTF8String]] = true;
+ }
}
- [pool release];
}
+ (void)toggleDebugOption:(id)menuItem
View
26 Frameworks/SoftwareUpdate/src/DownloadWindowController.mm
@@ -48,20 +48,18 @@ - (id)initWithURL:(NSString*)aURL displayString:(NSString*)aDisplayString keyCha
- (void)performBackgroundDownload:(id)sender
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
-
- shared_state_ptr state = sharedState;
- std::string error = NULL_STR;
- std::string path = sw_update::download_update(to_s(self.url), keyChain, &error, &state->progress, &state->stop);
-
- NSDictionary* arg = [NSDictionary dictionary];
- if(path != NULL_STR)
- arg = @{ @"path" : [NSString stringWithCxxString:path] };
- else if(error != NULL_STR)
- arg = @{ @"error" : [NSString stringWithCxxString:error] };
- [self performSelectorOnMainThread:@selector(didPerformBackgroundDownload:) withObject:arg waitUntilDone:NO];
-
- [pool drain];
+ @autoreleasepool {
+ shared_state_ptr state = sharedState;
+ std::string error = NULL_STR;
+ std::string path = sw_update::download_update(to_s(self.url), keyChain, &error, &state->progress, &state->stop);
+
+ NSDictionary* arg = [NSDictionary dictionary];
+ if(path != NULL_STR)
+ arg = @{ @"path" : [NSString stringWithCxxString:path] };
+ else if(error != NULL_STR)
+ arg = @{ @"error" : [NSString stringWithCxxString:error] };
+ [self performSelectorOnMainThread:@selector(didPerformBackgroundDownload:) withObject:arg waitUntilDone:NO];
+ }
}
- (void)updateProgress:(NSTimer*)aTimer
View
31 Frameworks/SoftwareUpdate/src/SoftwareUpdate.mm
@@ -147,25 +147,24 @@ - (IBAction)checkForUpdates:(id)sender
- (void)performBackgroundVersionCheck:(NSDictionary*)someOptions
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
+ @autoreleasepool {
+ NSURL* url = [someOptions objectForKey:@"infoURL"];
+ std::string error = NULL_STR;
+ auto info = sw_update::download_info(to_s([url absoluteString]), &error);
- NSURL* url = [someOptions objectForKey:@"infoURL"];
- std::string error = NULL_STR;
- auto info = sw_update::download_info(to_s([url absoluteString]), &error);
+ NSMutableDictionary* res = [[someOptions mutableCopy] autorelease];
+ if(error != NULL_STR)
+ {
+ [res setObject:[NSString stringWithCxxString:error] forKey:@"error"];
+ }
+ else
+ {
+ [res setObject:[NSString stringWithCxxString:info.url] forKey:@"url"];
+ [res setObject:@(info.version) forKey:@"version"];
+ }
- NSMutableDictionary* res = [[someOptions mutableCopy] autorelease];
- if(error != NULL_STR)
- {
- [res setObject:[NSString stringWithCxxString:error] forKey:@"error"];
- }
- else
- {
- [res setObject:[NSString stringWithCxxString:info.url] forKey:@"url"];
- [res setObject:@(info.version) forKey:@"version"];
+ [self performSelectorOnMainThread:@selector(didPerformBackgroundVersionCheck:) withObject:res waitUntilDone:NO];
}
-
- [self performSelectorOnMainThread:@selector(didPerformBackgroundVersionCheck:) withObject:res waitUntilDone:NO];
- [pool drain];
}
- (void)didPerformBackgroundVersionCheck:(NSDictionary*)info
View
26 Frameworks/ns/src/spellcheck.mm
@@ -12,9 +12,9 @@
spelling_tag_t::helper_t::~helper_t ()
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- [[NSSpellChecker sharedSpellChecker] closeSpellDocumentWithTag:_tag];
- [pool drain];
+ @autoreleasepool {
+ [[NSSpellChecker sharedSpellChecker] closeSpellDocumentWithTag:_tag];
+ }
}
template <typename _OutputIter>
@@ -37,21 +37,21 @@ _OutputIter spellcheck (char const* first, char const* last, std::string const&
std::vector<ns::range_t> spellcheck (char const* first, char const* last, std::string const& language, spelling_tag_t const& tag)
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
std::vector<ns::range_t> res;
size_t offset = 0;
- while(first != last)
- {
- char const* eol = std::find(first, last, '\n');
- spellcheck(first, eol, language, tag, offset, back_inserter(res));
- while(eol != last && *eol == '\n')
- ++eol;
- offset += eol - first;
- first = eol;
+ @autoreleasepool {
+ while(first != last)
+ {
+ char const* eol = std::find(first, last, '\n');
+ spellcheck(first, eol, language, tag, offset, back_inserter(res));
+ while(eol != last && *eol == '\n')
+ ++eol;
+ offset += eol - first;
+ first = eol;
+ }
}
- [pool drain];
return res;
}
View
6 Frameworks/ns/tests/t_key_events.mm
@@ -57,8 +57,8 @@ - (void)drawRect:(NSRect)aRect
public:
void test_key_events ()
{
- NSAutoreleasePool* pool = [NSAutoreleasePool new];
- OakSetupApplicationWithView([[[MyEventView alloc] initWithFrame:NSMakeRect(0, 0, 200, 100)] autorelease], "key_events");
- [pool drain];
+ @autoreleasepool {
+ OakSetupApplicationWithView([[[MyEventView alloc] initWithFrame:NSMakeRect(0, 0, 200, 100)] autorelease], "key_events");
+ }
}
};

0 comments on commit 983bce8

Please sign in to comment.
Something went wrong with that request. Please try again.