每当我创建一个新的View Controller子类时,Xcode都会自动添加该方法
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated
}
Run Code Online (Sandbox Code Playgroud)
通常我只是删除它或忽略它.这就是我所见过的所有教程.但我认为,因为Xcode每次都给我,所以它应该有点重要,对吧?我该怎么办?我假设处理资源意味着将它们设置为nil,但究竟什么是"可以重新创建的资源"?
我看过这些问题:
但他们都是斯威夫特之前.虽然我对Objective-C了解不多,但我听说内存管理不同.这对我应该做的事情didReceiveMemoryWarning有何影响?
其他说明:
didReceiveMemoryWarning,我发现这是相当短暂.这真让我抓狂!!!
每当我尝试使用sourceType = UIImagePickerControllerSourceTypeCamera显示UIImagePickerController时,我都会收到"已接收内存警告.级别= 1".
这是我在viewDidLoad中设置的代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Set card table green felt background
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"green_felt_bg.jpg"]];
// Init UIImagePickerController
// Instantiate a UIImagePickerController for use throughout app and set delegate
self.playerImagePicker = [[UIImagePickerController alloc] init];
self.playerImagePicker.delegate = self;
self.playerImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
Run Code Online (Sandbox Code Playgroud)
这是我如何以模态呈现它..
- (IBAction) addPlayers: (id)sender{
[self presentModalViewController:self.playerImagePicker animated:YES];
Run Code Online (Sandbox Code Playgroud)
}
结果...... UIImagePicker开始显示然后繁荣......我得到了记忆警告......每一次!有趣的是,如果我切换到sourceType = UIImagePickerControllerSourceTypePhotoLibrary ......一切正常.
我错过了什么或做错了什么?我想做的就是显示相机,拍摄并保存图片.
仅供参考 - 我正在测试我的3GS设备.
感谢任何能提供帮助的人 :)
iphone objective-c uiimagepickercontroller didreceivememorywarning
我是新开发者,即将推出我的第一款应用.我对viewDidUnloadApple的iOS 6发行说明中所述的弃用感到困惑:
在iOS 6中,现在不推荐使用UIViewController的viewWillUnload和viewDidUnload方法.如果您使用这些方法来释放数据,请改用didReceiveMemoryWarning方法.如果未使用此方法,也可以使用此方法释放对视图控制器视图的引用.在执行此操作之前,您需要测试视图不在窗口中.
为什么会这样?我应遵循哪些指导原则来确保此更改不会在我的应用中导致任何性能问题?
谢谢.
cocoa-touch objective-c didreceivememorywarning viewdidunload ios6
在iOS 6中,viewWillUnload并viewDidUnload已被取消,UIViewControllers不再卸载观点,即内存警告时不显示在屏幕上.该视图控制器编程指南对如何手动还原此行为的一个例子.
这是代码示例:
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Add code to clean up any of your own resources that are no longer necessary.
if ([self.view window] == nil)
{
// Add code to preserve data stored in the views that might be
// needed later.
// Add code to clean up other strong references to the view in
// the view hierarchy.
self.view = nil;
}
}
Run Code Online (Sandbox Code Playgroud)
代码示例下面是以下注释:
下次访问视图属性时,视图将与第一次完全重新加载.
这里有一个明显的缺陷.如果未加载其视图的视图控制器收到内存警告,它将在该行中加载其视图if ([self.view window] …
任何人都可以帮我解决这个问题我对目标c和iOS有点新意.我一直在努力,但我无法弄清楚如何解决问题,我的应用程序非常简单它只启动相机拍照并通过电子邮件发送到我们的服务器.这段代码在iOS6中运行得很好.
当我拍照时,我的内存是每次屏幕捕获的堆增长,我得到"接收内存警告",最后 - 由于内存压力终止. -
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController2 dismissPopoverAnimated:true];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
_image = [info
objectForKey:UIImagePickerControllerOriginalImage];
_image = [self fixrotation:_image]; //<----- increased memory when UIImageWriteToSavedPhotosAlbum is uncommented IF is comment it doesn't increased memory but after some pictures I start to get "Received Memory Warning" message until the app Crash.
if (_newMedia){
UIImageWriteToSavedPhotosAlbum(_image,
self,@selector(image:finishedSavingWithError:contextInfo:),
nil);
[self dismissViewControllerAnimated:NO completion:nil];
[self performSegueWithIdentifier:@"SeleccionadoCameraR" sender:self];
}else{
[self performSegueWithIdentifier:@"SeleccionadoCameraR" sender:self];
}
}
}
- (UIImage …Run Code Online (Sandbox Code Playgroud) memory-management uiimagepickercontroller didreceivememorywarning ios ios7
didReceiveMemoryWarning当我的应用程序在iPad模拟器上处于后台状态时,我注意到我的视图控制器没有调用他们的方法.更具体地说,我applicationDidEnterBackground在我的日志中看到调用,然后我点击"模拟内存警告"按钮,然后我注意到一个特殊的缺乏任何didReceiveMemoryWarning呼叫.
但是,当我将应用程序带回前台时,我突然didReceiveMemoryWarning接到呼叫,好像它已经排队了.
我在这里感到困惑的是,如果我的应用程序真的在后台,或者它只是暂停了.有没有办法告诉模拟器?
此外,如果它尚未暂停,而且实际上只是在后台,那么我会觉得愚蠢,我无法处理didReceiveMemoryWarning.因为这意味着只有前台应用程序才能处理内存警告以释放空间,这当然很奇怪,前景应用程序可能只是可能数十个正在运行的应用程序中的一个,如果它们会更有意义都可以释放记忆.
无论如何,主要问题是:为什么我不didReceiveMemoryWarning进入后台状态?而且,我真的被停职了吗?我怎么说?
您将看到一个空白屏幕(窗口).测试项目以演示此错误/问题:http://github.com/chetanpungaliya/iOS-5-TestModal
这不是一个问题,更多的是我在Apple提供的针对iOS4和5相机操作提供的AVCam示例代码周围发现的内容的记录.对我来说问题的症状是我的应用程序在拍摄5-10张照片后启动AVCamViewController时会崩溃.
我通过内存泄漏分析器运行应用程序并且没有明显的泄漏但是在使用Activity Monitor检查时我发现每次启动摄像头时称为mediaserverd的东西增加了17Mb,当它达到~100Mb时,应用程序崩溃了多个低记忆警告.
在新的iOS 6中,viewDidUnload不推荐使用,我们已被指示使用它didReceiveMemoryWarning来管理UIViewController实例和子类中的对象.将nils分配给内部的UIView didReceiveMemoryWarning类似于内部的方式同样有效viewDidUnload吗?
我问这个是因为这两种方法似乎有所不同.似乎didReceiveMemoryWarning不能保证viewDidLoad再次调用以重新实例化任何必要的UIViews.
我怀疑在iOS 6中,内存管理完成后无需手动解除分配UIView.请帮助我了解在理解UIViewController的生命周期时我错过了什么.
uiviewcontroller didreceivememorywarning ios viewdidunload ios6
我的应用程序使用了大量内存.通常它运行正常,但是在一段时间内没有重新启动的加载设备上,它将被抛弃臭名昭着的低内存错误.
我想回应didReceiveMemoryWarning并释放一些我的缓存.
但我有一个问题,我的应用程序是基于OpenGL ES模板,没有视图控制器.它只有App Delegate,它包含对glView的引用.
如何捕获didReceiveMemoryWarning消息以便我可以做出响应?
ios ×5
ios6 ×3
cocoa-touch ×2
iphone ×2
objective-c ×2
avcam ×1
ios5 ×1
ios7 ×1
low-memory ×1
opengl-es ×1
swift ×1
xcode ×1