4

short question: someone (cit. 5) told me that resident memory could be reclaimed by my system. What does this mean? Does it mean that my App is not using that memory or is the resident memory value directly related to the memory being currently used by my App? I haven't found much documentation on this apart from those answers.

I am trying to solve an issue. I am writing a game usign iOS 6.0 and Cocos2d 2.0 and I do get some memory problems. I have Cococs2d 2.0 as static library and I wrote my code using ARC (which I suspect being the reason).

Going from Initial scene to Character Selection Scene and then to Planet Selection scene and finally Game scene I observe that the resident_size of memory increases.

I added this code at each scene init and I tracked down the values. The following picture show the user experience path I do. On the left colum there are the scene names, on the second colum the amount of memory used in the normal flow (not going back to the previous scene) and in the third block of colums there are the values of resident memory going back and forwards from specific scenes.

enter image description here

As we can observe the Main scene presents an issue probably different from the other scenes. Every time I load the scene I get a memory increase of about 15 MB.

I run an indipendent test on the scene (using a reload callback method) and I get the following values:

enter image description here

Interestingly, running the same test on the CharacterSelection Scene does not have a progressive increase of memory after the third load (stays 37MB). However I do not understand why initially goes from 27 MB to 32 MB and NOT to 37MB (or, I should say, I do not understand why it goes from 32 MB to 37 MB).

I run another set of test trying to parse from one scene to the other and I do get interesting results. Here is the schema:

enter image description here

**Someone answered to me saying "Resident memory is a measurement of the memory that has been allocated to your application and has not yet been reclaimed by the system, but some/most of the resident memory could be reclaimed by the system."

Does this mean that resident memory values are not necessarily memory used by my App?

According to my test, there does seem to be a correlation between scenes and their memory used and resident memory value.

So if this is correct I should keep trying to solve this issue as the higher the resident memory value is the more likely my APP is to be killed. If, instead the memory would be available to the system to be used then there would be no crash. Given that there are crashes I assume that the memory is somehow leaked. However the leak tool does not detect any leaks (is this because I am using XCode 4.5?).

Any help? Is this related to using ARC?

Community
  • 1
  • 1
mm24
  • 9,280
  • 12
  • 75
  • 170
  • 1
    Just to be clear, is Instruments still saying that your app's "live bytes" is very small compared to the resident memory? And the Leaks instrument is reporting no leaks? If so, the next thing I would try is explicitly asking the Allocations instrument for the number of live instances of your various scene objects. (I'm assuming that when you go to the next scene the previous scene should be deallocated, and that there is some sort of master Scene class that contains everything that goes into a scene.) I suspect that you're leaking scenes and Instruments just isn't reporting those leaks. – Aaron Golden Sep 05 '13 at 18:35
  • @AaronGolden thanks Aaron, that's the case. Good suggestion. I will try it, update with a comment and if it works accept the answer (so you can add this as edit if u feel like). Thanks again for ur support :) – mm24 Sep 05 '13 at 19:36

1 Answers1

2

The issue was that I was measuring the memory during the init method of the new scene. The report was hence including the assets of the previous scene (as it was not yet being deallocated).

Adding a callback with a 0.1 delay solved it and answering my questions:

Q:

someone (cit. 5) told me that resident memory could be reclaimed by my system. What does this mean? Does it mean that my App is not using that memory or is the resident memory value directly related to the memory being currently used by my App?

A:

it is the memory directly related to the memory being used by my App. Using a delay in the callback of this function plus a call to [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo]; will confirm this.

Q:

Any help? Is this related to using ARC?

A: Not in this case fortunately. There where other issues causing leaks in some scenes. For example, the starting scene was subclass of another scene. This starting scene had some child nodes being added as child which where not being removed on the cleanup method of the scene. Adding an explicit removal of those child nodes solved the issue. I am not sure why this was necessary (I was expecting all child nodes to be automatically removed) but it solved the issue.

Community
  • 1
  • 1
mm24
  • 9,280
  • 12
  • 75
  • 170