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)
{
…
![](../../users/profiles/1845209.webp)
user1845209
- 2,221
- 2
- 16
- 16
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…
![](../../users/profiles/272342.webp)
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…
![](../../users/profiles/979498.webp)
one09jason
- 1,871
- 2
- 14
- 14
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)…
![](../../users/profiles/138260.webp)
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…
![](../../users/profiles/499206.webp)
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…
![](../../users/profiles/79856.webp)
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…
![](../../users/profiles/294884.webp)
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];
}
![](../../users/profiles/141302.webp)
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
![](../../users/profiles/599528.webp)
Jacob
- 13,463
- 58
- 188
- 302
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…
![](../../users/profiles/137147.webp)
Michael
- 3,249
- 2
- 20
- 16
22
votes
3 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?
![](../../users/profiles/1010171.webp)
sirab333
- 3,502
- 8
- 37
- 54
21
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?
![](../../users/profiles/365256.webp)
Howard
- 17,155
- 33
- 104
- 173
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…
![](../../users/profiles/242933.webp)
ma11hew28
- 106,283
- 107
- 420
- 616
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 =…
![](../../users/profiles/87158.webp)
samvermette
- 39,555
- 25
- 108
- 143
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…
![](../../users/profiles/147537.webp)
Z O.
- 2,636
- 3
- 20
- 27