Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 废弃内存问题_Ios_Objective C_Memory_Abandoned Memory - Fatal编程技术网

Ios 废弃内存问题

Ios 废弃内存问题,ios,objective-c,memory,abandoned-memory,Ios,Objective C,Memory,Abandoned Memory,你能帮我一下吗,我的应用程序快完成了,我正在优化它,所以我在使用仪器分配工具,我在视图控制器上遇到了问题,但我不明白为什么每次从主视图转到detailedViewController时内存都会增加 以下是似乎是问题所在的代码部分: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Create and push a detail view cont

你能帮我一下吗,我的应用程序快完成了,我正在优化它,所以我在使用仪器分配工具,我在视图控制器上遇到了问题,但我不明白为什么每次从主视图转到detailedViewController时内存都会增加

以下是似乎是问题所在的代码部分:

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Create and push a detail view controller.

    self.entriesDetailedViewController = [[EntriesDetailedViewController alloc]init];

Entry *selectedEntry = (Entry *)[[self fetchedResultsController] objectAtIndexPath:indexPath];

self.entriesDetailedViewController.entry = selectedEntry;

[self.navigationController pushViewController:self.entriesDetailedViewController animated:YES];
[self.entriesDetailedViewController release];
}
以下是detailedViewController.h的代码:

  #import <UIKit/UIKit.h>


  @class Entry;

 @interface EntriesDetailedViewController : UIViewController <UITextViewDelegate> {

//IBOutlet UIButton *createEntryButton;
IBOutlet UITextField *entryTextField1;
IBOutlet UITextView *entryTextField2;
IBOutlet UIBarButtonItem *textbodyBarButton;
IBOutlet UIBarButtonItem * catLabel;
IBOutlet UINavigationBar *entryNameToolBar;
IBOutlet UINavigationBar *textBodyToolBar;
IBOutlet UIImageView *reviewCheck;
IBOutlet UIImageView *textBackground;
IBOutlet UIBarButtonItem *reviewButton;
BOOL isChecked;

NSManagedObjectContext *managedObjectContext;


Entry *entry;

    }


 @property (nonatomic,retain) IBOutlet UITextField *entryTextField1;
 @property (nonatomic,retain) IBOutlet UITextView *entryTextField2;
 @property (nonatomic,retain) IBOutlet UIBarButtonItem *textbodyBarButton;
 @property (nonatomic,retain) IBOutlet UIBarButtonItem *catLabel;
 @property (nonatomic,retain) IBOutlet UINavigationBar *entryNameToolBar;
 @property (nonatomic,retain) IBOutlet UINavigationBar *textBodyToolBar;
 @property (nonatomic,retain) IBOutlet UIImageView *reviewCheck;
 @property (nonatomic,retain) IBOutlet UIBarButtonItem *reviewButton;
 @property BOOL isChecked;
 @property (nonatomic,retain) IBOutlet UIImageView *textBackground;

 @property (nonatomic,retain) NSManagedObjectContext *managedObjectContext;
 @property (nonatomic, retain) Entry *entry;


 - (void)setUpUndoManager;
 - (void)cleanUpUndoManager;
 - (void)textViewDidBeginEditing:(UITextView *)entryTextField2;
 - (void)textViewDidEndEditing:(UITextView  *)entryTextField2;
 - (void)saveContext;



 - (IBAction)dismisskeyboard;
 - (IBAction)dismissKeyboardfromTextView;
 - (IBAction) selectReview;


 @end
对不起,这是一段很长的代码,我知道,但我不知道。请帮帮我

按照你们的建议,我做了以下修改:

我还更改了代码的viewDidUnload和Dealloc部分,现在看起来如下所示:


我不太理解release+nil的概念,也不太理解在dealloc中调用[self.object release]和[object release]与在viewDidUnload中调用self.object=nil之间的区别。

每次分配新的
EntriesDetailedViewController
时,您的内存使用都会增加。我猜你的意思是当你释放它的时候你的记忆不会下降?您可能没有在
-[EntriesDetailedViewController解除锁定]
中正确发布某些内容


请注意,与其每次都生成一个新的
EntriesDetailedViewController
,不如在第一次需要时创建一个,然后继续使用
setEntry:
重新配置它。您已经将ivar设置为容纳视图控制器;不妨利用它。

每次分配新的
EntriesDetailedViewController
时,您的内存使用量都会增加。我猜你的意思是当你释放它的时候你的记忆不会下降?您可能没有在
-[EntriesDetailedViewController解除锁定]
中正确发布某些内容


请注意,与其每次都生成一个新的
EntriesDetailedViewController
,不如在第一次需要时创建一个,然后继续使用
setEntry:
重新配置它。您已经将ivar设置为容纳视图控制器;不妨利用这一点。

从您发布的代码来看,原因并不明显,但Instruments会向您显示每次分配发生的位置,因此应该不难找到。

从您发布的代码来看,原因并不明显,但Instruments会向您显示每次分配发生的位置,因此,追踪它应该不难。

您应该在dealloc中使用此表单:

[entryTextField1 release],entryTextField1=nil

您应该使用此表单设置(例如在
viewDidUnload
中):

self.entryTextField1=nil

运行静态分析应该会发现更多的问题。修好它们

一旦所有这些都得到纠正,然后重新运行应用程序。(我认为这不是100%的保险范围)

另外,请确保使用版本控制。你会发现自己在寻找很多问题——在它们全部解决之前,你应该期待更多的问题/崩溃


不幸的是,你无法永远避免内存问题,在学习正确的内存管理的同时,追踪其中一些问题是很痛苦的。祝你好运

您应该在dealloc中使用此表单:

[entryTextField1 release],entryTextField1=nil

您应该使用此表单设置(例如在
viewDidUnload
中):

self.entryTextField1=nil

运行静态分析应该会发现更多的问题。修好它们

一旦所有这些都得到纠正,然后重新运行应用程序。(我认为这不是100%的保险范围)

另外,请确保使用版本控制。你会发现自己在寻找很多问题——在它们全部解决之前,你应该期待更多的问题/崩溃


不幸的是,你无法永远避免内存问题,在学习正确的内存管理的同时,追踪其中一些问题是很痛苦的。祝你好运

嘿嘿,你知道什么家伙吗?我刚刚发现了!!!!!!!! 我是多么愚蠢。。。 如果仔细查看entriesDetailedViewController.h文件,可以看到有一个声明为。。。嗯,它没有发布,我已经忘记了那个

所以我很抱歉让你浪费时间

我刚才补充说:

    self.textbodyBarButton = nil;
[textbodyBarButton release];
现在我很好,当我回到rootViewController时,所有的内存都被释放了

所以,如果有一天你们也有同样的问题,这可能是愚蠢的。只需检查两次您在.h文件中声明的内容

哇,花了三天的时间在这上面


向你们大家致敬,再次感谢你们的耐心。

嘿,嘿,你们知道吗?我刚刚发现了!!!!!!!! 我是多么愚蠢。。。 如果仔细查看entriesDetailedViewController.h文件,可以看到有一个声明为。。。嗯,它没有发布,我已经忘记了那个

所以我很抱歉让你浪费时间

我刚才补充说:

    self.textbodyBarButton = nil;
[textbodyBarButton release];
现在我很好,当我回到rootViewController时,所有的内存都被释放了

所以,如果有一天你们也有同样的问题,这可能是愚蠢的。只需检查两次您在.h文件中声明的内容

哇,花了三天的时间在这上面


非常感谢大家,再次感谢你们的耐心。

你们的
-viewDidLoad
在不释放的情况下分配一个条形按钮项:
self.navigationItem.rightbuttonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:uibarbuttonSystemSave目标:self action:@selector(save:)]