简体   繁体   English

iOS开发:如何加强核心数据的内存使用量?

[英]iOS Development: How can I tighten up my Core Data memory usage?

I'm very new to Core Data and I'm still learning how it all works under the hood. 我对Core Data并不陌生,但我仍在学习如何在后台进行所有工作。 My Core Data model hierarchy contains a user profile, which contains a set of ten different levels using a one-to-many relationship, with each level containing 30 different puzzles also using a one-to-many relationship. 我的核心数据模型层次结构包含一个用户配置文件,该用户配置文件包含使用一对多关系的十个不同级别的集合,每个级别也包含三十个不同的难题(也使用一对多关系)。

UserProfile (x1) -> Level (x10) -> Puzzle (x30), for a grand total of 311 objects per user profile

The levels and puzzles models are used to store the user's progress as the user sequentially solves the puzzles. 当用户顺序解决难题时,级别和难题模型用于存储用户的进度。 When the game runs for the first time, the game reads all the levels and puzzles data from a plist and generates Core Data objects (table rows) that will be used store the users progress as they play the game. 当游戏首次运行时,游戏会从plist读取所有关卡并解谜数据,并生成Core Data对象(表行),这些对象将用于存储用户在玩游戏时的进度。 In other words, the list of Core Data objects doesn't grow as the user plays the game, instead it's all created at the start and the properties of the objects change as the user plays the game. 换句话说,Core Data对象的列表不会随着用户玩游戏而增长,而是在开始时全部创建,并且对象的属性会随着用户玩游戏而改变。 I suspect this is inefficient, tho my questions remain the same... 我怀疑这效率低下,但我的问题还是一样...

  1. When I load a user profile from Core Data, will is also load all ten levels, as well as the 30 puzzles for each level into memory? 当我从Core Data加载用户个人资料时,是否还会将所有十个级别以及每个级别的30个难题都加载到内存中? I ask because I obviously don't need all that data if the player is only playing one level at a time. 我问是因为如果玩家一次只玩一个关卡,我显然不需要所有这些数据。
  2. If all the level and puzzle data is loaded into memory when the user profile is loaded, how can I "lazy load" the level and puzzle data as it's needed? 如果在加载用户个人资料时所有的关卡和拼图数据都已加载到内存中,我如何才能根据需要“延迟加载”关卡和拼图数据?
  3. When I run my game using the Allocations instrument, it shows it's using 6MB of "Overall" memory when the app is fully loaded and sitting in the main menu. 当我使用分配工具运行游戏时,表明应用程序完全加载并位于主菜单中时,它正在使用6MB的“总体”内存。 Obviously, the memory usage increases as the user dives deeper into the navigation stack. 显然,随着用户深入导航堆栈,内存使用量会增加。 Is 6MB considered "a lot" of memory for an app that just started? 对于刚刚启动的应用程序,6MB是否被视为“大量”内存?
  4. I've noticed that when I comment out the line of code that loads the User's profile from Core Data, 6MB is still used. 我注意到,当我注释掉从Core Data加载用户的个人资料的代码行时,仍然使用6MB。 Does this mean the impact that my Core Data objects have on memory are negligible? 这是否意味着我的核心数据对象对内存的影响可以忽略不计?

I apologize if these are outrageous questions and I apologize for their length, and thanks so much for your wisdom! 对于这些令人毛骨悚然的问题,我深表歉意。对于它们的冗长,我深表歉意,并非常感谢您的智慧! I'm heading back to the Core Data docs right now, I just thought I'd post these questions while I continue the self-teaching. 我现在回到核心数据文档,我只是想在继续自我教学的同时发布这些问题。

This answers your 'lazy load' question. 这回答了您的“延迟加载”问题。 Core Data to-many relationships. 核心数据对多关系。 Are they Lazy Load? 他们是懒加载吗?

I wouldn't worry about 6MB of memory unless you see a performance issue. 除非您看到性能问题,否则我不会担心6MB的内存。 You can always check it with the included utilities. 您始终可以使用随附的实用程序进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 核心数据 - 内存使用情况:我的应用程序崩溃了 - Core Data - memory usage: my app crashes iOS开发:如何在设备上引发低内存警告? - iOS Development: How can I induce low memory warnings on device? 如何在Core Data中指定基数以进行iOS开发 - How to specify cardinality in Core Data for iOS development iOS开发:如何缩短代码中的URL? - iOS Development: How can I shorten a URL from my code? iOS开发:如何从模式视图返回数据? - iOS Development: How can I return data from a modal view? iOS开发:我可以在Core Data对象中存储整数数组而无需创建表示数组的新表吗? - iOS Development: Can I store an array of integers in a Core Data object without creating a new table to represent the array? iOS开发:为什么我不能将我的plist数据附加到我的MFMailComposeViewController? - iOS Development: Why can't I attach my plist data to my MFMailComposeViewController? iOS /核心数据 - 如何更改NSFetchedResultsController的sectionNameKeyPath? - iOS / Core Data - How can I change sectionNameKeyPath of a NSFetchedResultsController? 在处理Core Data时如何停止建立内存? - How do I stop a build up of memory when dealing with Core Data? iOS开发:如何使视图向右过渡而不是默认向左过渡? - iOS Development: How can I make my view transition to the right instead of to the default left?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM