0

I'm observing iTunes using the NSDistributedNotificationCenter class.
This method is called when iTunes plays a new track. The implementation is empty.

Strangely, when I have ARC enabled, there is some memory allocated every time this method observeITunes: method gets called. Apparently, this memory is never released.

enter image description here

No matter how long I wait, this memory is never released.

So I found this strange and made an empty test-project, copying the relevant code there.
In the test-project there is no memory allocation visible at all (Which is correct).


Code

[[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                    selector:@selector(observeITunes:)
                                                        name:@"com.apple.iTunes.playerInfo"
                                                      object:nil];

- (void)observeITunes:(NSNotification *)notification {
    // Empty method
}

Can anyone explain this phenomenon to me?
I couldn't find an answer.

bneely
  • 9,083
  • 4
  • 38
  • 46
IluTov
  • 6,807
  • 6
  • 41
  • 103
  • Use the 'mark heap' feature of Instruments to mark the points in time when this empty method would theoretically execute, then examine the new allocation types for each heap. – bneely Mar 06 '14 at 17:43
  • @bneely How do I do that? Sorry, I don't have a lot of experience with Instruments. – IluTov Mar 06 '14 at 17:48
  • Here's a link to Apple documentation and a screenshot of Instruments showing the Mark Heap button: https://developer.apple.com/library/ios/documentation/AnalysisTools/Reference/Instruments_User_Reference/AllocationsInstrument/AllocationsInstrument.html#//apple_ref/doc/uid/TP40011355-CH40-SW10 . You use the Allocations instrument, then press Mark Heap at significant events while running your app. Then you can examine changes between marked heaps and get a list of new allocations. – bneely Mar 06 '14 at 17:56
  • How many observers do you add? – Hot Licks Mar 06 '14 at 18:02
  • @HotLicks Just that one – IluTov Mar 06 '14 at 18:08
  • And only once? `addObserver` isn't inside the loop? – Hot Licks Mar 06 '14 at 18:11
  • @HotLicks Which loop? No it's called once in `init` – IluTov Mar 06 '14 at 18:20
  • The loop created by cycling through the tunes. – Hot Licks Mar 06 '14 at 18:22
  • @HotLicks No I just use iTunes to skip through the tracks. – IluTov Mar 06 '14 at 18:25
  • 1
    So `addObserver` is only called once, for the entire app? And iTunes isn't caching anything? – Hot Licks Mar 06 '14 at 18:26
  • @HotLicks Yes. I'm not sure what it should cache. It's a simple notification. – IluTov Mar 06 '14 at 18:32

0 Answers0