我有一个包含多页信息的UIScrollView,这些信息作为子视图添加到scrollView中。每个子视图的控制器都存储在scrollViewController的NSMutableArray中。
我在子视图中有一些内存泄漏,我试图通过确保调用每个子视图控制器的dealloc方法来修复它们。我通过在scrollView控制器的dealloc方法中释放视图控制器来做到这一点。
在释放subViews控制器之后,当我尝试释放数组时,应用程序崩溃。
代码如下...我做错了什么?
- (void)dealloc {
// Loop through the array of subView contr
假设我有以下场景:
- (void)someFunction:(id)param {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSObject *objectA = [[NSObject alloc] init];
[objectA doStuff]; // Don't need to release objectA because of the pool
if (!someValue) {
[pool release]; // Doubt her
目前我正在为一个结构动态分配内存,之后我将为它的一个成员动态分配内存。我的问题是,我应该也释放成员,还是只释放结构,为什么? #include <stdlib.h>
struct test{
char *test_member;
};
int main(){
struct test *new_test;
// Allocating memory for structure and its member
new_test = (test*)malloc(sizeof(test));
new_test->test_member = (char*)ma