0

Ok so this is a pretty vague question but let me give you some background:

I have a straight forward app so far - about 5 screens each of which will hit the database and display some information on the resultant view. The objects aren't huge, about 15 attributes some of which would be NSSets with 3-4 objects contained.

I've noticed that by the time I'm on my 5th screen, memory has jumped to nearly 6mb which seems huge to me (though I could be wrong).

I do notice a 1mb jump every time I do a DB call like NSFetchRequest which uses the usual NSManagedObjectContext, NSPersistentStoreCoordinator, etc as you'd expect.

Do I need to close the context when I'm done with the DB or something like that? I remember such Persistence Contexts causing huge memory problems back in my Java days and since there's nothing else going that (I believe) can really be taxing the app thats where I'd guess the issue is.

I'm using ARC and CoreData.

Any insight into this would be really appreciated.

Update

So I used Instruments as recommended (great tool btw) and it looks as though the problem is caused by one screen with about 30-40 UILabels (resulting in a use of about 4MB). Seems like a lot of memory for UILabels or am I completely off?

4

1 回答 1

1

每个UIView人都有一个CALayer。因此,每个视图最终都会缓存其内容。假设您的 30–40 个标签最终填满了屏幕,并且您使用的是 iPhone 4,那么您会期望它们的内存占用至少为 960*640*4 = 2.4mb。我敢打赌他们会占据更多的空间。

如果您正在遭受痛苦,请忽略将其视为巨大浪费的本能,因为:

  • 在 iOS 5 和更早版本下,如果出现内存警告,那么任何离屏视图控制器都会释放它们的视图;和
  • 在 iOS 6(可能是更高版本)下,如果出现内存警告,则附加到所有屏幕外视图的图层会释放其内容。

因此,通常情况下,内存仅在可用时才被使用——这是一个简单的问题,不要仅仅因为它可能并不总是可用而忽略资源。

于 2013-07-24T21:10:45.673 回答