Questions tagged [retain]

551 questions
212
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) { …
141
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,205
  • 6
  • 60
  • 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…
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
  • 701
  • 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,051
  • 6
  • 29
  • 36
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,598
  • 10
  • 48
  • 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
  • 30,632
  • 54
  • 336
  • 607
30
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]; }
senthilMuthu
  • 9,258
  • 18
  • 74
  • 139
29
votes
8 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