Questions tagged [autorelease]

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

References

414 questions
84
votes
13 answers

How to find the cause of a malloc "double free" error?

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…
gonso
  • 2,065
  • 5
  • 27
  • 35
73
votes
1 answer

What is autoreleasepool?

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…
moray95
  • 937
  • 2
  • 9
  • 12
19
votes
3 answers

What's the difference between sending -release or -drain to an Autorelease Pool?

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.…
Thanks
  • 40,109
  • 71
  • 208
  • 322
19
votes
2 answers

Is there a way to create an NSDecimal without using NSNumber and creating autoreleased objects?

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…
Urizen
  • 2,331
  • 6
  • 23
  • 33
17
votes
4 answers

Object was probably modified after being freed

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…
Stone
  • 171
  • 1
  • 1
  • 3
17
votes
3 answers

iOS autorelease pool blocks

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…
Teo
  • 3,394
  • 11
  • 43
  • 73
16
votes
2 answers

When is an autoreleased object actually released?

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…
16
votes
2 answers

How to know if an object is autoreleased or not?

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…
quano
  • 18,812
  • 25
  • 97
  • 108
15
votes
1 answer

Why does Xcode 4.2 use @autoreleasepool in main.m instead of NSAutoreleasePool?

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, …
Foo
  • 596
  • 2
  • 5
  • 21
15
votes
2 answers

ARC equivalent of autorelease?

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?
eonil
  • 83,476
  • 81
  • 317
  • 516
14
votes
5 answers

Why is autorelease especially dangerous/expensive for iPhone applications?

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…
e.James
  • 116,942
  • 41
  • 177
  • 214
11
votes
5 answers

When does autorelease actually cause a release in Cocoa Touch?

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…
Ian1971
  • 3,666
  • 7
  • 33
  • 61
11
votes
1 answer

Does @"some text" give an autoreleased or retain 1 object back?

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…
Binarian
  • 12,296
  • 8
  • 53
  • 84
11
votes
1 answer

What is the correct way to use realm in an autoreleasepool?

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…
fisher
  • 1,286
  • 16
  • 29
11
votes
4 answers

Is it dangerous to set off an autoreleased NSOperationQueue?

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…
bastibe
  • 16,551
  • 28
  • 95
  • 126
1
2 3
27 28