retain

NSTimer bad access

痞子三分冷 提交于 2019-12-11 09:00:46
问题 I'm trying to create an NSTimer, then invalidate and release it, then set it to a new timer. However, I am getting an EXC_BAD_ACCESS when trying to set the timer member var again. Code below: 1) I set the timer member var (it's set to retain) self.mPageTimer = [NSTimer scheduledTimerWithTimeInterval:kPageTimerInterval target:self selector:@selector(pageTimerCallback) userInfo:nil repeats:NO]; 2) I let it go [mPageTimer invalidate]; [mPageTimer release]; This results in the crash when I try to

Does @property (readonly, retain) have a meaning?

▼魔方 西西 提交于 2019-12-11 08:59:16
问题 XCode accepts it. But will retain be applied when I internally set the property (no setter outside since readonly but when I initialize the value in a class method) ? Regards, Apple92 回答1: The reason to do this is to allow you to do @property (retain) in a class continuation or category. If you don't have the retain on the outer property, you will get a warning about the properties being mismatched. 回答2: You might specify (readonly, retain) for a publicly-facing property, and then inside your

Retain radio button selection after submit - PHP

谁说胖子不能爱 提交于 2019-12-11 07:39:37
问题 I am experiencing an issue with radio buttons present on my page, can anyone tell me why it wont retain its selection after the user has pressed submit? <?php session_start(); if(isset($_POST['submit'])) if(!empty($_POST['diet'])) ?> ... <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <strong>Dietary Requirements:</strong> <br><br> Vegetarian <input type="radio" name="diet" <?php if (isset($_POST['diet']) && $_POST['diet']=="Vegetarian") echo "checked";?>

UIViewController retain problem: count never reaches zero

ε祈祈猫儿з 提交于 2019-12-11 05:05:23
问题 Please, take a look at my code bellow. This part pops top view controller (usually, the same ArticleControllerController ) from the stack (I found that the problem stays the same no matter if I pop single controller or pop to the root controller), creates new one and adds to the stack. The problem is, that its retain count never goes to zero and so dealloc method of ArticleControllerController is never called leaving large amounts of various interface objects unreleased. Eventually app

Property attribute “retain” doesn't seem to be working?

只愿长相守 提交于 2019-12-11 03:05:02
问题 I've implemented a bit of code from one of the many Apple code examples, but I'm having a bit of trouble, because the retain attribute of one of the properties doesn't appear to be working. Here's the property declaration: @property (nonatomic, retain) EditingViewController *editingViewController; And here's the code: - (EditingViewController *)editingViewController { // Instantiate the editing view controller if necessary. if (editingViewController == nil) { EditingViewController

iOS中的内存管理(上)

天大地大妈咪最大 提交于 2019-12-10 14:22:07
下列行为都会增加一个app的内存占用: 1、创建一个OC对象; 2、定义一个变量; 3、调用一个函数或者方法。 如果app占用内存过大,系统可能会强制关闭app,造成闪退现象,影响用户体验。如何让回收那些不再使用的对象呢?本文着重介绍OC中的内存管理。 所谓内存管理,就是对内存进行管理,涉及的操作有: 1、分配内存:比如创建一个对象,会增加内存占用; 2、清除内存:比如销毁一个对象,会减少内存占用。 内存管理的管理范围: 1、任何继承了NSObject的对象; 2、对其他非对象类型无效(int、char、float、double、struct、enum等) 只有OC对象才需要进行内存管理的本质原因: 1、OC对象存放于堆里; 2、非OC对象一般放在栈里面(栈内存会被系统自动回收) 系统是如何判断什么时候需要回收一个对象所占用的内存呢?在这里涉及到对象的“引用计数器”的概念。 引用计数器: 每个OC对象都有自己的引用计数器,它是一个整数;每个OC对象内部都有4个字节的存储空间来存放引用计数器。 从字面上看,引用计数器可以理解为“对象被引用的次数”。 简单来说,可以理解为: 引用计数器 表示有多少人正在使用这个对象。 当没有任何人使用这个对象时,系统才会回收这个对象;也就是说: 1、当对象的引用计数器为0时,对象占用的内存就会被系统回收; 2、如果对象的计数器不为0

how to retain my uitextfield values in viewController when i calling?

我的梦境 提交于 2019-12-10 11:54:18
问题 I have a main page having 3 textfield in my first view as i navigate to different view and return back to my first view (i.e after i enter all the values i moving to next page).I want my 3 textfield to retain its value when i go back to my main page here my sample code : NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *mobile = MobileNum.text; [defaults setObject:mobile forKey:self.MobileNum.text]; NSString *amountText = amount.text; [defaults setObject:amountText

Checking for a valid delegate object before sending it a message

六眼飞鱼酱① 提交于 2019-12-10 10:15:46
问题 I am trying to implement the delegate Pattern in Objective-C, however I am experiencing a Bad Access exception when invoking the delegate sometimes. It seems this is caused by the delegate being released. Apple does not recommend to retain delegates. How can I check my delegate if is still valid before trying to send it a message? 回答1: If there's a chance that the delegate will get released by the setter, then there's something wrong with your design. You should only set delegates on objects

Properties in Objective c. copy and retain

北慕城南 提交于 2019-12-09 07:12:51
问题 What I have read from the apple document retain will increase the retain count by 1 , and release will decrease by 1. This is very much clear to me. But In the case of copy and retain i am a bit confused. Let me explain with the code i am trying. property --- @property(nonatomic, retain) NSMutableString *a; @property(nonatomic, copy) NSMutableString *b; @synthesize a = _a ,b = _b a=[[NSMutableString alloc]initWithString:@"Hello Ankit"]; NSLog(@"a memory location A - %p", &a ); b=[

How can I retain CGPDFDictionaryRef?

隐身守侯 提交于 2019-12-08 12:00:34
问题 Any ideas how to "retain" CGPDFDictionaryRef? CFRetain not working, but there must be way to "retain" it. 回答1: From the documentation This opaque type is not derived from CFType and therefore there are no functions for retaining and releasing it. CGPDFDictionary objects exist only as constituent parts of a CGPDFDocument object, and they are managed by their container. 回答2: A CGPDFDictionaryRef is just a pointer to a struct. Thus, you can easily retain it when boxed into a NSValue. Of course