autorelease

Autorelease pools in appkit applications

六月ゝ 毕业季﹏ 提交于 2019-12-10 00:36:30
问题 I'm having difficulties to understand exactly WHEN autorelease pools are created and released in AppKit apps. For example, if I have an ApplicationController class that overrides init, is there an autorelease pool that gets created before it starts and gets drained after it ends? 回答1: The main thread in an AppKit application runs an NSRunLoop to process events. NSRunLoop creates a new autorelease pool every time it processes a new event (or timer) and drains it once control flow has returned

Objective-C - autoreleasepool (ARC - Automatic reference Counting)

江枫思渺然 提交于 2019-12-08 05:34:22
问题 I have a doubt regarding autoreleasepool in an Auto Reference Counting (ARC) In my example (pasted below) I have an autoreleasepool and I have no statements within the autoreleasepool block. There is an autoreleased instance (a3) after the autoreleasepool block. Expected Behavior: I expected the following statement to cause a memory leak because it is not encapsulated with in an autoreleasepool. A* a3 = b1.xa1; Actual Behavior: Actual behavior is that no memory leak error is thrown at runtime

Need clarification for NSAutoreleasePool

梦想的初衷 提交于 2019-12-07 16:52:06
问题 Whenever we are calling autorelease method, its object is going to NSAutoreleasePool . When the pool is drained, it is sending release to all the objects in the pool. My question is; In the main function there is one NSAutoreleasePool . I want to know that; when we call the autorelease method, where it is sending the object ? I mean; it is sending the object to NSAutoreleasePool which is in main function (or) somewhere ? Thanks in advance. 回答1: There is actually a stack of autorelease pools.

iPhone - Objective-C Memory Leak with SBJsonParser

試著忘記壹切 提交于 2019-12-06 19:37:25
I keep getting the following memory leak using the "Leaks" tool in Xcode. As this is a library, I'm just wondering what would be the best way to fix such a leak. Any help would be greatly appreciated. I am happy to share more code if needed. UPDATE: I found this article, which doesn't seem promising. Has anyone got any suggestions as to how to fix this? http://code.google.com/p/json-framework/issues/detail?id=13 This is how I'm using the library. - (void)getFacebookProfileFinished:(ASIHTTPRequest *)request { NSString *responseString = [request responseString]; NSMutableDictionary *responseJSON

is the main.m really the place, where the autorelease pool of the main run loop is created by every event?

风格不统一 提交于 2019-12-06 11:37:50
问题 #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSLog(@"new event..."); NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } If that's the case, then the main() function would have to be called on every event, right? But I tried it, and the "new event..." log message comes just on app start. So I guess that there must be another autorelease pool in the main thread. 回答1: No. All Cocoa or

Objective-C - weak property - getter autoreleases (Automatic Reference Counting)

寵の児 提交于 2019-12-06 04:46:23
问题 I have a doubt regarding weak property in ARC (auto reference counting) My understanding (correct me if I am wrong): weak property behaves similar to the assign property except that when the instance that the property was pointing to gets destroyed, the ivar is made to point to nil. Question: I just feel that the getter of the weak property retains and autoreleases. Isn't it suppose to behave like getter of the assign property where the getter doesn't retain and autorelease ?(pls refer to the

NSURLCache crashes with autoreleased objects, but leaks otherwise

[亡魂溺海] 提交于 2019-12-06 02:23:52
问题 CSURLCache is designed to cache resources for offline browsing, as NSURLCache only stores data in-memory. If cachedResponse is autoreleased before returning the application crashes, if not, the objects are simply leaked. Any light that could be shed onto this would be much appreciated. Please note stringByEncodingURLEntities is a category method on NSString . @interface CSURLCache : NSURLCache {} @end @implementation CSURLCache - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *

Need clarification for NSAutoreleasePool

落花浮王杯 提交于 2019-12-06 01:50:00
Whenever we are calling autorelease method, its object is going to NSAutoreleasePool . When the pool is drained, it is sending release to all the objects in the pool. My question is; In the main function there is one NSAutoreleasePool . I want to know that; when we call the autorelease method, where it is sending the object ? I mean; it is sending the object to NSAutoreleasePool which is in main function (or) somewhere ? Thanks in advance. DarkDust There is actually a stack of autorelease pools. Whenever you do [[NSAutoreleasePool alloc] init] that newly created pool is automatically put on

__weak and autorelease pool in ARC in Xcode 4.2

与世无争的帅哥 提交于 2019-12-05 18:39:24
My project use ARC. I tested with the code below: NSString __weak *string; @autoreleasepool { string = [NSString stringWithString:@"AAA"]; } NSLog(@"string: %@", string); I think it output as: string: (null) but it actually output: string: AAA I don't understand it. What is the effect of __weak? EDIT: And this code below: NSString __weak *string; NSString __strong *str; @autoreleasepool { str = [NSString stringWithFormat:@"%@", @"AAA" ]; string = str; } NSLog(@"string: %@", string); It also output as: string: AAA NSString __weak *string; @autoreleasepool { string = [NSString stringWithFormat:@

What's the right way to set an NSError outparam from inside an autoreleasepool block?

江枫思渺然 提交于 2019-12-05 02:44:51
I have a method like this: - (void)processAThing:(id)thing error:(NSError * __autoreleasing *)error { @autoreleasepool { // Start processing. // Find some partway through error.. if (error) { *error = [NSError errorWithDomain...]; return NO; } // More processing. } } This is broken and crashes, because the NSError is autoreleased, and when the return happens, the pool is drained, so the thing that the caller gets is now bogus. I know I could significantly redesign the method so I collect all error cases outside the autorelease block, but I want to understand whether there's a correct way of