问题标签 [memory-warning]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
510 浏览

objective-c - 防止实例变量在内存警告时被清除

我有一个相对简单的问题,一段时间以来一直在逃避解决方案。我有一个视图控制器和一个关联的 XIB。视图控制器称为FooterViewController. FooterViewController的视图设置为 tableview 的页脚视图。

FooterViewController的视图包括一个用于向用户显示反馈的标签。我希望这个标签一直存在,直到它的值被我的应用程序更改。在正常情况下,确实如此。但是,我刚刚开始使用内存警告进行测试,我发现在卸载视图以响应内存警告后,标签被清除。

到目前为止,这是我为解决问题所做的尝试:在FooterViewController's viewWillUnload方法中,我将标签的文本存储在一个名为的实例变量中statusString

请注意,我还将另一个实例变量(声明为NSInteger testInt)设置为 5。

然后,在FooterViewController'sviewDidLoad方法中,我尝试将标签的文本设置为statusString

但是,这不起作用。此外,在模拟内存警告后的日志中,我看到:

(注意“Invalid IP address Error code: 113”是statusString的正确值)

然后,FooterViewController再次导航到后,我看到:

这向我表明,由于某种原因,FooterViewController当视图再次加载时,实例变量正在重新初始化。最后一点:initWithNibName:bundle:每次必须重新加载视图时都会调用该方法,尽管我希望如此;毕竟,视图必须从 NIB 重新加载。

所以,我的问题是:

  1. 为什么这些实例变量在卸载和重新加载视图的过程中似乎被取消或归零?
  2. 如果我做错了导致这种无效的事情,那是什么?
  3. 如果我没有做错任何事情,这是正常行为,我应该如何处理视图加载之间的维护状态?

谢谢,莱利

0 投票
1 回答
1224 浏览

ios - iOS - 收到内存警告

该应用程序播放捆绑包中的视频和音频。当我在我的 iPod Touch 上测试应用程序时,有时就在视频播放之前,它会记录消息。有时,当应用程序想要准备音频播放器(在另一个视图控制器中)时,它会记录消息。

但是我还没有崩溃!:D 我不确定如果它在其他打开多个应用程序的设备上运行是否会发生崩溃。那么,我应该担心这个吗?我应该在另一个线程中准备AudioPlayer 或moviePlayer 吗?还是忽略它?

0 投票
1 回答
421 浏览

iphone - iPhone SDK:内存警告后 UIBarButtonItem 不刷新

我正面临着一个非常奇怪的行为UIBarButtonItem

我已经能够在下面粘贴代码的测试应用程序中重现该错误。

在我的第一个视图中,我有一个显示 GUID 的标签、一个转到空的第二个视图的按钮和一个UIBarButtonItem. 如果我单击它,它的颜色会从绿色变为红色,反之亦然,并且 GUID 会更新。

以下是如何重现它:

  • 转到第二个视图
  • 发出内存警告(在模拟器硬件菜单中,但与设备上的真实内存警告相同)
  • 回到第一个
  • 点击UIBarButtonItem

UIBarButtonItem即使是以前也不会令人耳目一新,并且日志显示一切似乎都是正确的。

视图控制器.h

视图控制器.m

和故事板:

故事板

它影响 Simulator 5.0 和 5.1,以及 5.1.1 上的设备

编辑:通过记录 self.aButton 的值,我看到它nil在内存警告之后,由于weak关键字。但我怎样才能重新分配它?SDK不应该自己做吗?为什么aGUID仍然可用?

编辑:这是一个日志。我们可以看到 aButton 变为 nil。

0 投票
1 回答
349 浏览

ios - iPad SplitViewController Memory Warning Causes Problems With Master View

I have an iPad SplitViewController application with the following features:

  • master (left hand) view controller is hidden in both portrait and landscape by returning YES in the shouldHideViewController delegate method
  • master view controller contains a tab bar controller
  • I utilise a multiple master detail manager to manage swapping the detail view controller based upon the selection made by the user in the master tab bar

I have a problem that only occurs after a memory warning is received by the application. When the master view slides in (either via a swipe or tapping the left bar button) the view appears effectively empty i.e. it does not contain any table view, just the semi-transparent background where the table view should be. If I tap the other view in my tab bar it loads it's master view correctly. If I then tap back to the problem view it now appears correctly.

Originally I had another problem in that not only was the view empty but it was also sized for full screen. I was able to fix the size problem via the solution proposed in this SO question - it is noted in the solution that "Apparently when a memory warning is received, the view controller gets released, so when it presents itself again, it gets it's size from it's parent view, which is full screen. So you just have to reset the frame every time it gets loaded."

By putting break points in my code I can verify that when I first try to access the master view after a memory warning the ViewDidLoad event is called (this does not occur if there has not been a memory warning), however the ViewDidAppear & ViewWillAppear events are not called. So the app is aware that it needs to reload the master view after a memory warning, but for some reason it does not seem to show the master view.

I'm struggling to work out how to correctly make the view appear again after a memory warning. Or is there something I should be doing to prevent the master view from being unloaded when a memory warning is received?

UPDATE: I have also observed that if the master view is showing at the time of the memory warning then this problem does not occur.

0 投票
2 回答
461 浏览

ios - 内存问题 - 生活与整体 -> 应用程序被杀死

我正在尝试在 Instruments 中检查我的应用程序内存问题。当我加载应用程序时,我会播放一些声音并在 UIImageViews 中显示一些动画。为了节省一些内存,我只在需要时加载声音,当我停止播放时,我将它从内存中释放出来。

问题1:

我的应用程序使用了大约 5.5MB 的 Living 内存。但是整体部分在开始到 20MB 后开始增长,然后缓慢增长(大约 100kB/秒)。但是负责的库是 OpenAL (OAL::Buffer)、dyld (_dyld_start)——我不确定这到底是什么,还有一些其他的东西,比如 ft_mem_qrealloc、CGFontStrikeSetValue,……

问题2:

当整个部分超过 30MB 时,应用程序崩溃(被杀死)。根据我已经阅读的有关整体内存的事实,这意味着我的所有分配和释放大约是 30MB。但我真的看不出问题所在。例如,当我需要一些声音时,我将它加载到内存中,当我不再需要它时,我释放它。但这意味着当我加载 1MB 声音时,此操作会增加 2MB 的整体内存使用量。我对吗?当我加载 10 种声音时,我的应用程序崩溃只是因为我的总体水平太高,即使生活仍然很低???我对此感到非常困惑。

有人可以帮我清理一下吗?

(我在 iOS 5 上并使用 ARC)

一些代码:

创建声音 OpenAL:

播放:

使用 AVAudioPlayer 创建声音:

并停止并释放它:

和图像动画:我从大 PNG 文件加载图像(这也适用于我的另一个主题:https ://stackoverflow.com/questions/12223714/memory-warning-uiimageview-and-its-animations )我有几个 UIImageViews 和到时候我正在设置动画数组来播放动画......

我只是简单地使用这个数组:

0 投票
1 回答
444 浏览

iphone - 内存警告和崩溃的应用程序 - 找不到问题的根源

在收到许多内存警告后,我的应用程序不断崩溃。它有将近三万行代码,因此很难跟踪问题。我已经通过仪器运行它,并且在某些阶段有高达 30MB 的实时字节,据我所知,这应该不是太大的问题。内存泄漏极少,因此它们不会成为问题。该应用程序在长时间播放后往往会崩溃。仪器中没有任何东西可以帮助我追踪我不断收到的记忆警告的来源。有没有其他可能的方法来做到这一点?非常重要的是,这不会因为明显的原因而发生。任何帮助是极大的赞赏。

0 投票
2 回答
590 浏览

iphone - 在 iPhone 上使用图像和相机时出现内存问题

在我的应用程序中,用户最多可以添加 8 张由相机拍摄的图像,并将它们一张一张上传到服务器。我的问题是,即使在拍摄第一张照片时,我也会收到内存警告,这当然会强制应用程序释放任何不可见的视图。

处理图片的最佳实践方法是什么?我如何在不耗尽内存的情况下保留它们直到它们被上传?

我的目标是避免任何内存警告。

提前致谢。

/埃斯本

0 投票
2 回答
841 浏览

objective-c - 核心数据故障和内存警告

NSManagedObject 是否观察到内存警告并变成故障?我应该在记忆力紧张的情况下做这种事情吗?

是否有关于使用 Core Data 保留内存的指南?

0 投票
3 回答
1528 浏览

ios - 在我的服务器上上传 100 多张图片时收到内存警告和应用程序崩溃

我正在使用以下代码在服务器上上传 100 多张图片,并且在上传几张图片后收到内存警告。请帮助我..这是我在服务器上上传图片的代码:

0 投票
1 回答
528 浏览

ios - 仪器和泄漏

我有一个应用程序,我正在对其进行分析。我对仪器很陌生,我也是一个很新的 ios 开发人员。我正在使用 ios6 并且我有一个非常不寻常的泄漏。我在 UIImage 上创建了一个类别,并添加了帮助方法来返回图像以使用 capinset。我的类别看起来像这样,

仪器显示该区域有 3/4 泄漏,同一个地方,我无法找出原因。是这样吗,我必须发布我在类别中创建的新图像,如果我发布它我要返回什么?任何人都可以解释我在这里泄漏内存的原因。

我像这样使用它;

以这种方式使用这种方法有什么问题吗?