Use autorelease for questions related to deferring the release of a variable stored within an object until some time in the future to facilitate referencing it while avoid memory leaks
I'm programming an application in Objective-C and I'm getting this error:
MyApp(2121,0xb0185000) malloc: *** error for object 0x1068310: double free
*** set a breakpoint in malloc_error_break to debug
It is happening when I release an…
Possible Duplicate:
Why use Autorelease pool?
All Objective-C starting page opens with a default @autoreleasepool{...} statement under the main function declaration. But what is this statement actually doing? The new Objective-C releases…
In many Books and on many Sites I see -drain. Well, for an Autorelease Pool that sounds cool. But does it do anything other than an release? I would guess -drain just makes the Pool to -release all it's objects, without releasing the Pool itself.…
I am carrying out a number of calculations using NSDecimal and am creating each NSDecimal struct using the following technique:
[[NSNumber numberWithFloat:kFloatConstant] decimalValue]
I am using NSDecimal to avoid using autoreleased…
I am working on a project on iPhone. I am now initiating a new UIViewController from another UIViewController, and then switch between them. Here is my code.
iGreenAppDelegate *delegate = [UIApplication…
I was reading the documentation from apple about memory management when I got to autorelease pool blocks and something got me thinking.
Any object sent an autorelease message inside the autorelease pool block is
released at the end of the…
I am new in objective-c and I am trying to understand memory management to get it right.
After reading the excellent
Memory Management Programming Guide for Cocoa by apple my only concern is when
actually an autoreleased object is released in an…
I'm getting a a bit annoyed about some objects being autoreleased without me knowing. It's probably a good thing that they are, but if they are, I want to know. The documentation doesn't say which methods autorelease objects, so I usually test my…
I've noticed that there is a different way in Xcode 4.2 to start the main function:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
…
If I have this code,
+ (MyCustomClass*) myCustomClass
{
return [[[MyCustomClass alloc] init] autorelease];
}
This code guarantees the returning object is autoreleased.
What's the equivalent of this in ARC?
I'm looking for a primary source (or a really good explanation) to back up the claim that the use of autorelease is dangerous or overly expensive when writing software for the iPhone.
Several developers make this claim, and I have even heard that…
I understand you need to be careful with autorelease on iOS. I have a method that is returning an object it allocs which is needed by the caller, so in this situation -- as I understand it -- I need to send autorelease to the object in the callee…
Given this code:
// Initialize string
NSString *name = @"Franzi";
@"" macro creates a NSString with given text (here the name Franzi) and a RETAIN COUNT OF 1?
So @"" gives an NSString with have to be released or not? Am I responsible for this…
This is what the documentation has to say about accessing a realm using GCD:
"You should use an explicit autorelease pool when accessing a Realm from a dispatch queue."
Documentation
I have used this practice in my app but I am suddenly seeing the…
I have a task that takes a rather long time and should run in the background. According to the documentation, this can be done using an NSOperationQueue. However, I do not want to keep a class-global copy of the NSOperationQueue since I really only…