Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Instruments using lots of memory.

Okay so this is my issue and I apologize if its a duplicate. I searched but couldn't find anything I considered relevant.

When I run instruments from xcode and begin testing my application for memory leaks or allocations my iMac eventually begins to run very very slowly.

This caused me to run activity monitor while using instruments and I notice that every second instruments is open it takes up more and more real memory. Roughly 100MB's a sec.

It doesn't take long for it to consume all my iMacs free memory (2gbs) and then it starts to lag.

Anyways this doesn't occur with every application. I've done the same test with some application/projects I downloaded and instruments only seems to use about 250mbs of space and doesn't dramatically increase.

Is there something obvious that I'm doing incorrectly? Any help would be appreciated.

Thanks.

like image 360
Tasik Avatar asked Aug 30 '11 01:08

Tasik


1 Answers

instruments consumes a lot of memory.

depending on what you are recording, you may reduce its memory usage. for example, you can often specify what (or what not) to record, or lower sampling frequencies(if applicable).

100MB/s is unusually high. can you give a more exact description of what you are recording in that time? (instruments you use, what the process you record is doing, etc).

Xcode 3 used a lot less memory - not sure if that's also the case for Instruments.

You can reduce the memory usage somewhat by running the toolset as 32 bit processes.

lastly, 2GB physical memory is nothing for Xcode + Instruments + iOS Sim. fwiw, i regularly exhaust physical memory with 8 or more GB. boo. fortunately, memory is cheap when you want 4 or 8GB.

Update

I tried using instruments for Allocations, Leaks and Zombies

You can run these tests individually, if you must.

Allocations

By itself, allocations should not consume a ton of memory if your app is not creating a lot of allocations.

To reduce memory with this instrument, you can disable some options you are not interested in:

  • do not record each ref count operation
  • only track active allocs
  • disable zombie detection
  • do not identify c++ objects

Leaks

  • implies Allocations instrument only if you want history of leaks.

Leaks detection itself can consume a lot of memory because it scans memory, basically cloning your allocations. say you have 100MB allocated - leaks will periodically pause the process, clone the memory and scan it for patterns. this could consume more memory than your app. iirc, it's executed as a subprocess in instruments.

Zombies

  • implies Allocations instrument.

Zombie detection usually implies ref count recording. When debugging zombies, it's most effective to never free them. If you do free them, you may only detect transient zombies (not sure if there's an option for that in instruments...). Never freeing objc allocations will obviously consume more memory. Running leaks on a process will then consume more memory because your heap sizes will be larger - leaks and zombies should not be combined.

you should be able to reduce total consumption by disabling some of these options and testing for them individually.

Notes

  • The bleeding edge Developer Tools releases can be really shaky. If you are having problems, it helps to stick to the official releases.
  • I can run a osx unit test (primarily c/c++ apis) with allocations alone, it consumes about 1MB/s when recording. something seems wrong, but perhaps that indicates an issue in your program (many transient allocations?).
  • changing the way the data is displayed and/or the charge/focus settings can require a lot of memory. e.g. "Restore All" can require a few GB to process a large sample.
  • if 100MB/s is an accurate number, i'd file a bug. I know Instruments consumes a lot of memory, but that's very high for recording an idle app, even with the expectation that instruments consumes a lot of memory.

good luck

like image 70
justin Avatar answered Nov 07 '22 19:11

justin