Questions tagged [retain]
569 questions
221
votes
7 answers
capturing self strongly in this block is likely to lead to a retain cycle
How can I avoid this warning in xcode. Here is the code snippet:
[player(AVPlayer object) addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(0.1, 100)
queue:nil usingBlock:^(CMTime time) {
current+=1;
if(current==60)
{
…

user1845209
- 2,311
- 2
- 18
- 17
144
votes
7 answers
Fix warning "Capturing [an object] strongly in this block is likely to lead to a retain cycle" in ARC-enabled code
In ARC enabled code, how to fix a warning about a potential retain cycle, when using a block-based API?
The warning:
Capturing 'request' strongly in this block is likely to lead to a retain cycle
produced by this snippet of code:
ASIHTTPRequest…

Guillaume
- 21,685
- 6
- 63
- 95
80
votes
4 answers
@property definitions with ARC: strong or retain?
Using Xcode 4.2 and ARC, I notice that the auto-generated code for an NSManagedObject still reads like this for properties:
@property (nonatomic, retain) NSString * someString;
1) Shouldn't retain now be replace with strong or weak?
2) Why does the…

one09jason
- 1,931
- 2
- 14
- 15
54
votes
8 answers
Objective-C 101 (retain vs assign) NSString
A 101 question
Let's say i'm making database of cars
and each car object is defined as:
#import
@interface Car:NSObject{
NSString *name;
}
@property(nonatomic, retain) NSString *name;
Why is it @property(nonatomic, retain)…

qstar
- 711
- 1
- 8
- 11
43
votes
10 answers
Non-retaining array for delegates
In a Cocoa Touch project, I need a specific class to have not only a single delegate object, but many of them.
It looks like I should create an NSArray for these delegates;
the problem is that NSArray would have all these delegates retained, which…

wh1t3cat1k
- 3,146
- 6
- 32
- 38
39
votes
6 answers
What happens if I don't retain IBOutlet?
If I do this:
@interface RegisterController : UIViewController
{
IBOutlet UITextField *usernameField;
}
instead of this:
@interface RegisterController : UIViewController
{
UITextField…

Jordan
- 21,746
- 10
- 51
- 63
34
votes
6 answers
Is there a way to "find mystery retains" ...?
Recently I was repairing someone's code. There was a big class that would not dealloc. You'd have to hit it with 5 or 6 releases to get it to dealloc.
I carefully looked through the big class and eventually found the various things that needed to…

Fattie
- 27,874
- 70
- 431
- 719
31
votes
9 answers
What is the difference between "copy" and "retain"?
What is the difference between copy and retain for NSString?
- (void)setString:(NSString*)newString
{
string = [newString copy];
}
user141302
30
votes
4 answers
Swift: how to log out retain count of objects?
Is there a way to quickly log out the retain count of objects to Xcode's Console?
If not, what's the next best alternative?

sirab333
- 3,662
- 8
- 41
- 54
29
votes
9 answers
Selected value for JSP drop down using JSTL
I have SortedMap in Servlet to populate drop down values in JSP and I have the following code
SortedMap dept = findDepartment();
request.setAttribute("dept ", dept);
and in JSP

Jacob
- 14,463
- 65
- 207
- 320
25
votes
3 answers
Objective C release, autorelease, and data types
I'm new to memory managed code but I get the idea pretty well.
On taking my app through the leaks tool in XCode, I noticed I only had to clean up my custom objects, but not dynamically created arrays for example, so I figured those data types are…

Michael
- 3,269
- 2
- 23
- 16
22
votes
4 answers
NSArray property: copy or retain?
According to this: NSString property: copy or retain?
For NSString/NSMutableString, copy is recommended.
How about NSArray/NSMutableArray?

Howard
- 19,215
- 35
- 112
- 184
19
votes
2 answers
Why retain a static variable?
Isn't it unnecessary to retain a static variable since it stays around for the duration of the program, no matter if you release it?
See this…

ma11hew28
- 121,420
- 116
- 450
- 651
19
votes
2 answers
iOS 4 blocks and retain counts
I'm just getting started with blocks and Grand Central Dispatch. I've been told (and read in the Apple Documentation) that any object referenced from within a block gets retained.
For instance:
^{
self.layer.transform =…

samvermette
- 40,269
- 27
- 112
- 144
19
votes
5 answers
IBOutlet instances are (null) after loading from NIB
I am working on an iPhone app and am getting (null) references to IBOutlet fields in my controller. I have a UIViewController subclass that is set as the File's Owner in my XIB. I have a set of UI elements that are wired into the controller. After…

Phoebe
- 2,774
- 3
- 22
- 27