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 object?
Second code example then confuses me, even though I am using it that way:
NSSting *message; message = [NSString stringWithFormat:@"Hello @%!",name]; //message = [NSString stringWithFormat:@"Hello Girl!"];
So message gets released in next run loop, k. But what is with the NSString given as argument for stringWithFormat?
Does the class object NSString release the NSString @”Hello %@”/@”Hello Girl” given as arguement?
Or does @””-Konstruktor only give back autoreleased NSStrings?
- Releasing objects returned by method
- Why does Xcode 4.2 use @autoreleasepool in main.m instead of NSAutoreleasePool?
- Use autorelease when setting a retain property using dot syntax?
- Objective-C autorelease pool not releasing object
- Autorelease vs. release
- What is the difference between releasing and autoreleasing?
Solutions Collect From Internet About “Does @“some text” give an autoreleased or retain 1 object back?”
NSString literal notation
@"" gives you compile-time constant strings that reside in their own memory space and have constant addresses.
Contrary to popular belief, the reason why you don’t release literal strings is not because they are part of the autorelease pool. They aren’t — instead, they spend the entire application’s lifetime in that same memory space they’re allocated at compile time, and never get deallocated at runtime. They’re only removed when the app process dies.
That said, the only time you need to memory-manage constant
NSStrings is when you retain or copy them for yourself. In that case, you should release your retained or copied pointers, just like you do any other object.
Another thing: it’s the literals themselves that don’t need memory management. But if you pass them as arguments to
NSString‘s convenience methods or initializers, like you do with
stringWithFormat:, then it’s those objects returned by the methods and initializers that follow all memory management rules normally.
- Swift String Interpolation displaying optional?
- Getting App Store URL before Apple Review
- Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)
- Doubts on concurrency with objects that can be used multiple times like formatters
- Reading data using glReadPixel() with multisampling
- Dynamic custom fonts loader in iOS
- ScrollView in SpriteKit
- NSArray of UIImages to video error has distortion in the output
- iOS Background Mode
- Emojis support in Apple push notification
- Xcode 4: My iPhone projects have become Mac OS projects.. and I can't change this
- How to create an Empty Application in Xcode 6 without Storyboard
- EXC_BAD_ACCESS only on xcode 8 running iOS 8
- How to init Fabric properly in Swift
- Autoresize UICollectionView height to adjust to its content size