ios - 收到内存警告的未知原因

标签 ios xcode uiimage instruments nsmutabledictionary

让我快点来发。到目前为止,我的代码没有问题。我唯一关心的是内存管理。让我让我的应用程序逻辑清晰。

  • 当应用程序全局启动时,声明了 NSmutableDictionary 并将近 300 个图像添加到该字典中,并使用 pathForResource:ofType 方法添加了各种键和图像。
  • 在我的 rootViewController 加载后,我的 35 个自定义 UIView 被添加到同一个全局字典中,并使用另一个键。(这个 rootViewController 不会经常使用)
  • 我有 4 个 ViewControllers,我将在其中使用这个 UIViews 和图像到全局字典中的所有 ViewControllers。
  • 当移动到另一个 View Controller 时,我释放 View 并使其为零。
  • 我的问题是当我在 ViewControllers 之间快速移动( 1 --> 2 --> 3 --> 4 -->1 )。如果我这样做 4 - 6 次,它就会崩溃。
  • 如果我慢慢移动,它会在 10 到 15 次后崩溃。

  • 即使我的 Live 字节最大为 5 MB,我也不知道它崩溃的原因。我从控制台和设备日志中得到的只是接收到的内存警告。使用仪器时无泄漏和无脏尺寸或常驻尺寸。

    在模拟器中运行时,我仅在多个设备上才遇到此问题,但我遇到了此问题。

    我有以下疑问
  • 在全局字典中添加所有内容是否好。我的想法是减少每个 ViewControllers 的加载时间
  • 为了重用相同的图像,我们可以使用 pathForResource 或图像命名方法..

  • 提前致谢 ...

    最佳答案

    所以你的问题:

    Unknown reason to receive Memory Warning



    第一个原因:

    When App is launched globally NSmutableDictionary is declared and nearly 300 images are added to that Dictionary with various keys and images are added using pathForResource:ofType method.



    第二个原因:

    After my rootViewController loaded my 35 custom UIViews are added to same global dictionary with another key.(this rootViewController will not be used often)



    其他问题:

    Whether its good to add everything in global dictionary. My idea is to reduce the loading time for every ViewControllers



    不,这不是... Lazy Initialization ?

    for reusing same images can we use pathForResource or image named method..



    你可以使用任何你想要的东西,只要你真正需要它时使用它。

    关于ios - 收到内存警告的未知原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15548033/

    相关文章:

    iphone - 反转 UIWebView 或 UITextView 中的颜色

    ios - 通过按钮对表格 View 中的单元格进行排序

    iphone - 使用 UIGestures 删除选定的 uiimage?

    android - 在 Windows 中获取 React Native IOS .ipa 文件

    ios - 为什么 Swift 不提供类成员初始化器?

    ios - 在 viewDidAppear 中以编程方式更改为 Tabbar 选项卡 View

    objective-c - 在 Objective C 中连接整数和字符串

    Objective-C:无法实例化类来创建 UINavigationController subview

    ios - UIImage 作为模式

    ios - 应用模糊渐变