- 浏览: 204430 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
feihumingyue:
nice 很好啊
JSF中如何使用FacesContext类 -
wgcniler:
请问如果传到存储过程的参数是一个嵌套表的话该怎么写?自定义的o ...
spring中调用存储过程 -
wgcniler:
请问如果传到存储过程的参数是ARRAY,但ARRAY的元素不是 ...
spring中调用存储过程 -
bengan:
谢谢楼上的提示
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案 -
gypgyp:
用xcode的菜单:product/profile,弹出窗口中 ...
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案
viewDidUnload viewDidLoad UIViewController内存管理相关的几个方法
viewDidLoad
view载入后的操作有:view显示的一些数据要在此载入,并在viewDidUnload时释放。
viewDidUnload
view释放后的操作有:释放那些view显示时的数据,并在view再次载入内存时也载入这些数据。
所以:获得数据应该是先判定是否存在。不存在再去获取。。这么个思路、
dealloc
Deallocates the memory occupied by the receiver.
- (void)dealloc
Discussion
Subsequent messages to the receiver may generate an error indicating that a message was sent to a deallocated object (provided the deallocated memory hasn’t been reused yet).
You never send a dealloc message directly. Instead, an object’s dealloc method is invoked indirectly through therelease NSObject protocol method (if the release message results in the receiver's retain count becoming 0). SeeMemory Management Programming Guide for more details on the use of these methods.
Subclasses must implement their own versions of dealloc to allow the release of any additional memory consumed by the object—such as dynamically allocated storage for data or object instance variables owned by the deallocated object. After performing the class-specific deallocation, the subclass method should incorporate superclass versions of dealloc through a message to super:
- (void)dealloc {
[companion release];
NSZoneFree(private, [self zone])
[super dealloc];
}
Important: Note that when an application terminates, objects may not be sent a dealloc message since the process’s memory is automatically cleared on exit—it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management methods. For this and other reasons, you should not manage scarce resources in dealloc—see Object Ownership and Disposal in Memory Management Programming Guide for more details.
didReceiveMemoryWarning
Sent to the view controller when the application receives a memory warning.
- (void)didReceiveMemoryWarning
Discussion
The default implementation of this method checks to see if the view controller can safely release its view. This is possible if the view itself does not have a superview and can be reloaded either from a nib file or using a customloadView method. If the view can be released, this method releases it and calls the viewDidUnload method.
You can override this method (as needed) to release any additional memory used by your view controller. If you do, be sure to call the super implementation at some point to allow the view controller to release its view. In iOS 3.0 and later, if your view controller holds references to objects in the view hierarchy, you should release those references in the viewDidUnload method instead. In earlier versions of iOS, you should continue to release them from this method. See the discussion in the viewDidUnload method for information about how to safely release outlets and other objects.
viewDidUnload
Called when the controller’s view is released from memory.
- (void)viewDidUnload
Discussion
This method is called as a counterpart to the viewDidLoad method. It is called during low-memory conditions when the view controller needs to release its view and any objects associated with that view to free up memory. Because view controllers often store references to views and other view-related objects, you should use this method to relinquish ownership in those objects so that the memory for them can be reclaimed. You should do this only for objects that you can easily recreate later, either in your viewDidLoad method or from other parts of your application. You should not use this method to release user data or any other information that cannot be easily recreated.
Typically, a view controller stores references to objects using an outlet, which is a variable or property that includes the IBOutlet keyword and is configured using Interface Builder. A view controller may also store pointers to objects that it creates programmatically, such as in the viewDidLoad method. The preferred way to relinquish ownership of any object (including those in outlets) is to use the corresponding accessor method to set the value of the object tonil. However, if you do not have an accessor method for a given object, you may have to release the object explicitly. For more information about memory management practices, see Memory Management Programming Guide.
By the time this method is called, the view property is nil.
Special Considerations
If your view controller stores references to views and other custom objects, it is also responsible for relinquishing ownership of those objects safely in its dealloc method. If you implement this method but are building your application for iOS 2.x, your dealloc method should release each object but should also set the reference to that object to nil before calling super.
viewDidLoad
view载入后的操作有:view显示的一些数据要在此载入,并在viewDidUnload时释放。
viewDidUnload
view释放后的操作有:释放那些view显示时的数据,并在view再次载入内存时也载入这些数据。
所以:获得数据应该是先判定是否存在。不存在再去获取。。这么个思路、
dealloc
Deallocates the memory occupied by the receiver.
- (void)dealloc
Discussion
Subsequent messages to the receiver may generate an error indicating that a message was sent to a deallocated object (provided the deallocated memory hasn’t been reused yet).
You never send a dealloc message directly. Instead, an object’s dealloc method is invoked indirectly through therelease NSObject protocol method (if the release message results in the receiver's retain count becoming 0). SeeMemory Management Programming Guide for more details on the use of these methods.
Subclasses must implement their own versions of dealloc to allow the release of any additional memory consumed by the object—such as dynamically allocated storage for data or object instance variables owned by the deallocated object. After performing the class-specific deallocation, the subclass method should incorporate superclass versions of dealloc through a message to super:
- (void)dealloc {
[companion release];
NSZoneFree(private, [self zone])
[super dealloc];
}
Important: Note that when an application terminates, objects may not be sent a dealloc message since the process’s memory is automatically cleared on exit—it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management methods. For this and other reasons, you should not manage scarce resources in dealloc—see Object Ownership and Disposal in Memory Management Programming Guide for more details.
didReceiveMemoryWarning
Sent to the view controller when the application receives a memory warning.
- (void)didReceiveMemoryWarning
Discussion
The default implementation of this method checks to see if the view controller can safely release its view. This is possible if the view itself does not have a superview and can be reloaded either from a nib file or using a customloadView method. If the view can be released, this method releases it and calls the viewDidUnload method.
You can override this method (as needed) to release any additional memory used by your view controller. If you do, be sure to call the super implementation at some point to allow the view controller to release its view. In iOS 3.0 and later, if your view controller holds references to objects in the view hierarchy, you should release those references in the viewDidUnload method instead. In earlier versions of iOS, you should continue to release them from this method. See the discussion in the viewDidUnload method for information about how to safely release outlets and other objects.
viewDidUnload
Called when the controller’s view is released from memory.
- (void)viewDidUnload
Discussion
This method is called as a counterpart to the viewDidLoad method. It is called during low-memory conditions when the view controller needs to release its view and any objects associated with that view to free up memory. Because view controllers often store references to views and other view-related objects, you should use this method to relinquish ownership in those objects so that the memory for them can be reclaimed. You should do this only for objects that you can easily recreate later, either in your viewDidLoad method or from other parts of your application. You should not use this method to release user data or any other information that cannot be easily recreated.
Typically, a view controller stores references to objects using an outlet, which is a variable or property that includes the IBOutlet keyword and is configured using Interface Builder. A view controller may also store pointers to objects that it creates programmatically, such as in the viewDidLoad method. The preferred way to relinquish ownership of any object (including those in outlets) is to use the corresponding accessor method to set the value of the object tonil. However, if you do not have an accessor method for a given object, you may have to release the object explicitly. For more information about memory management practices, see Memory Management Programming Guide.
By the time this method is called, the view property is nil.
Special Considerations
If your view controller stores references to views and other custom objects, it is also responsible for relinquishing ownership of those objects safely in its dealloc method. If you implement this method but are building your application for iOS 2.x, your dealloc method should release each object but should also set the reference to that object to nil before calling super.
发表评论
-
iOS 监听音量调节 事件
2013-08-14 12:18 1122iOS 监听音量调节 事件 做项目需要音量调节的事件来控制其 ... -
cocoa 图片操作若干
2012-08-23 01:19 1176转载自 http://stackoverflow.com/qu ... -
Objective-C的Properties
2012-08-21 18:20 1702Objective-C是苹果为Cocoa框架下设计的面向对象语 ... -
objective-c properties 概念
2012-08-21 17:50 837学了一段时间 objective-c properties 概 ... -
UIVideoEditorController 使用
2012-07-18 15:15 1719概述 不能定制界面,不可派生子类。 使用步骤: 检查制定源是否 ... -
iphone app 四种崩溃类型
2012-07-17 22:42 1201一.四种崩溃类型 程序崩溃: 可能是最常见的,经常发生于内存 ... -
首先查看crash log中的崩溃线程
2012-07-15 15:47 1961首先查看crash log中的崩溃线程,假如是这样的: Th ... -
iOS【EXC_BAD_ACCESS 】crash报告分析
2012-07-15 15:40 7995做iOS的开发者,经常都会遇到这个问题,我在这里做一下简单的分 ... -
objective-c aes加密
2012-05-11 11:21 3647在cocoa看到的加密代码,介绍一下。 aes加密的,1M的数 ... -
NSObject类所支持的一些基本方法
2012-04-10 14:33 1399NSObject类所支持的一些基本方法 对象是否class- ... -
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案
2012-03-31 11:52 2405关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的 ... -
Xcode4.2新特性之storyboards (故事板)
2012-03-31 11:43 4380Xcode4.2新特性之storyboards ... -
iPhone OS体系结构
2012-03-29 07:43 1796iPhone OS体系结构 iPhone OS有着绚丽优雅的外 ... -
iPhone的软件栈分成好几层
2012-03-29 07:01 1265iPhone的软件栈分成好几层。应用程序位于最高的抽象层,而系 ... -
UIImagePickerController使用
2012-03-17 22:47 4319UIImagePickerController使用 引用UI ... -
wait_fences: failed to receive reply: 10004003奇怪的错误
2012-03-17 11:09 2783今日遇到wait_fences: failed to rece ... -
iphone app 本地化程序名称
2012-03-17 01:38 994本地化程序名称 1、 建立InfoPlist.strings ... -
iphone app 为图片添加边框
2012-03-17 01:30 2588头文件中#import <QuartzCore/Quar ... -
objective-c 内存管理的文章摘录2
2012-03-15 01:09 902Cocoa内存管理规则 1)当 ... -
objective-c 内存管理的文章摘录1
2012-03-15 01:02 950今天有空想学习一下objective-c的内存管理的知识就上网 ...
相关推荐
在iOS开发中,了解UIViewController的生命周期方法至关重要,特别是`loadView`, `viewDidLoad`, 和 `viewDidUnload`。这三个方法在视图控制器的视图管理过程中扮演着不同的角色。 首先,我们来详细解读`loadView`。...
2. **View Controller**:每个`UIViewController`子类应当实现`didReceiveMemoryWarning`方法。当内存警告发生时,系统会调用此方法。默认情况下,如果控制器的`view`不在当前显示的视图层次结构中,且已实现了`...
3. `viewDidUnload`:在系统内存紧张时,如果UIViewController的视图不在当前的视图层次结构中,且控制器实现了`loadView`方法,系统会调用此方法。这里应该释放与视图相关的所有资源,包括IBOutlets并将其设置为nil...
本文将详细讲解标题“Cocoa常用类和方法”中涉及的几个核心类:UIViewController、UIView以及UILabel。 首先,我们来看UIViewController。它是iOS应用中控制器层的核心类,用于管理屏幕上的用户界面。...
`UIViewController` 是一个控制器类,它的主要职责是管理一个或者多个`UIView`实例。`UIViewController`的`view`属性是它默认显示的视图,你可以通过这个属性设置自定义的视图类。`initWithNibName:bundle:`是初始化...
- UIViewController显示过程中的方法调用顺序是init -> viewDidLoad -> viewDidAppear -> viewDidUnload。 代码题部分: 1. 计算二维数组对角线的值的和,可以通过双重循环实现,从第一行第一列开始,到最后一行...
nib 文件创建的,或者在`loadView`方法中调用了`super.loadView`,当收到内存警告并且View不再使用且已经消失时,ViewController会释放View并将指针置为nil,同时调用`viewDidUnload`方法。 #### 三、代码组织与...
- **解释**: `UIViewController`类中的方法按特定顺序被调用:首先调用`init`方法完成初始化,然后加载视图(`viewDidLoad`),当视图出现在屏幕上时调用`viewDidAppear`,最后当视图卸载时调用`viewDidUnload`。
1. UIViewController调用顺序:`initWithNibName:bundle:` -> `loadView` -> `viewDidLoad` -> 使用视图 -> `viewDidUnload` -> `dealloc`。`initWithNibName:bundle:`初始化,`loadView`加载视图,`viewDidLoad`...
在iOS开发领域,面试题通常会涵盖多个方面,包括但不限于设计模式、UI组件、网络通信、内存管理以及多线程等。以下是对标题和描述中提及的一些知识点的详细解释: **1. MVC(Model-View-Controller)架构模式:** ...
在iOS面试中,掌握核心知识点至关重要,这有助于应聘者展示其专业技能和理解力。...同时,还需要了解其他关键概念,如AutoLayout、手势识别、内存管理、动画、多线程优化、网络编程、Core Data等。
- **动态库**:与静态库不同,动态库在程序运行时由操作系统动态加载到内存中,多个程序可以共享同一份库的内存副本,从而节省空间。然而,动态库的使用需要确保运行环境已经安装了相应的库,否则程序可能无法运行...