retain

What happens if I don't retain IBOutlet?

半腔热情 提交于 2019-11-27 02:31:44
If I do this: @interface RegisterController : UIViewController <UITextFieldDelegate> { IBOutlet UITextField *usernameField; } instead of this: @interface RegisterController : UIViewController <UITextFieldDelegate> { UITextField *usernameField; } @property (nonatomic, retain) IBOutlet UITextField *usernameField; Will something bad happen? I know in the second case, the field is retained, but does this make a different since the nib owns the field? Will the field go away without the retain? and under what circumstances? The code in the first case works, was wondering whether this is an issue or

property “assign” and “retain” for delegate

断了今生、忘了曾经 提交于 2019-11-27 01:52:22
问题 For iOS developers, delegates are used almost everywhere. And seems like that we need to use "assign" instead of retain for a delegate like this @property(assign) id delegate; The reason is to avoid the circular loop issue Why are Objective-C delegates usually given the property assign instead of retain? I saw a lot of code and they still used "retain". So the question here is will we still get the circular loop issue if we use retain for a delegate? Thanks 回答1: The documentation says:

Objective C release, autorelease, and data types

梦想的初衷 提交于 2019-11-27 00:11:32
问题 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 autoreleased - makes sense since I only had to release the arrays I used as properties that had a (retain) on them. Then I noticed something peculiar : I was getting a leak on a certain array initialized like this : NSMutableArray *removals =

Selected value for JSP drop down using JSTL

ⅰ亾dé卋堺 提交于 2019-11-26 20:21:40
I have SortedMap in Servlet to populate drop down values in JSP and I have the following code SortedMap<String, String> dept = findDepartment(); request.setAttribute("dept ", dept); and in JSP <select name="department"> <c:forEach var="item" items="${dept}"> <option value="${item.key}">${item.value}</option> </c:forEach> </select> I am using one JSP page for insert and update. When I am editing the page how can I set selected value to drop down where selected value will come from database. BalusC In HTML, the selected option is represented by the presence of the selected attribute on the

@property definitions with ARC: strong or retain?

巧了我就是萌 提交于 2019-11-26 19:51:53
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 auto-generated code still use retain 3) What is the correct replacement for retain in this property statement? I'm currently debugging a problem using NSFetchRequest , and I thought this might be the source of the problem. Thoughts? 1) Shouldn't retain now be replace with strong or weak? No. You cannot replace retain with weak; they are different.

When to access properties with 'self'

有些话、适合烂在心里 提交于 2019-11-26 16:43:51
I have read a number of questions on this site about this issue, I understand the following: self.property accesses the getter/setter method created manually or by @synthesize. Depending upon whether the property is declared as retain, copy etc. the retain count is modified correctly, for example a retained property, releases the previous value assigned the new value with 'retain' and increments the retain count by 1. Properties are usually declared with instance variables of the same name (can be different if you make the assignment manually). This is generally because the @synthesize

Non-retaining array for delegates

我怕爱的太早我们不能终老 提交于 2019-11-26 12:36:52
问题 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 it shouldn\'t (by convention objects should not retain their delegates). Should I write my own array class to prevent retaining or are there simpler methods? Thank you! 回答1: I found this bit of code awhile ago (can't remember who to attribute it to)

What happens if I don&#39;t retain IBOutlet?

女生的网名这么多〃 提交于 2019-11-26 10:09:37
问题 If I do this: @interface RegisterController : UIViewController <UITextFieldDelegate> { IBOutlet UITextField *usernameField; } instead of this: @interface RegisterController : UIViewController <UITextFieldDelegate> { UITextField *usernameField; } @property (nonatomic, retain) IBOutlet UITextField *usernameField; Will something bad happen? I know in the second case, the field is retained, but does this make a different since the nib owns the field? Will the field go away without the retain? and

How many times do I release an allocated or retained object?

喜你入骨 提交于 2019-11-26 08:30:37
问题 I am making an iPhone game. I want to release all objects that have been allocated or retained. In the dealloc function I am releasing all such objects, but then I realized that sometimes I end up releasing objects when they have not been allocated yet. So I figured I need to check if its retainCount is greater than zero or not before I release it. My question is: Do I just check if the retainCount is greater than zero and then release it? if([bg retainCount]!=0) { [bg release]; } or Should I

Selected value for JSP drop down using JSTL

二次信任 提交于 2019-11-26 07:34:10
问题 I have SortedMap in Servlet to populate drop down values in JSP and I have the following code SortedMap<String, String> dept = findDepartment(); request.setAttribute(\"dept \", dept); and in JSP <select name=\"department\"> <c:forEach var=\"item\" items=\"${dept}\"> <option value=\"${item.key}\">${item.value}</option> </c:forEach> </select> I am using one JSP page for insert and update. When I am editing the page how can I set selected value to drop down where selected value will come from