3

Hi all I don't understand retain so well.

There is this code here:

mAppIcon = [[NSImage imageNamed:@"NSApplicationIcon"] retain];

I am trying to swizzle it so whenever they ask for image with name NSApplicationIcon I give it my custom icon. I still see the original icon come back sometimes. I think it's because of this retain thing? Am I right? is it possible to clear the retain? This will make my swizzle works 100% of time instead of only 80% as it does now :(

I read here about retain but I wasnt able to apply it to help my situation above: http://www.cocoawithlove.com/2010/06/assign-retain-copy-pitfalls-in-obj-c.html

Very specifically I am trying to swizzle this here: https://dxr.mozilla.org/mozilla-central/source/widget/cocoa/nsMacDockSupport.mm?offset=200#140

Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    That `retain` has nothing to do with it. If you have the source to the project, why not just change the icon? – bbum Oct 03 '15 at 06:24
  • Thanks @bbum, it's an addon for firefox so people want to dynamically set their icon. So its interesting, it works if the user does it after startup, but on startup/restart of browser, it sets the icon but 5sec after it reverts. So temporarily I have a work around where I set the icon a second time wih a timeout of 10sec. What does that `retain` do btw? – Noitidart Oct 03 '15 at 12:18
  • 2
    It is a memory management primitive; basically says that the object-- the image-- shouldn't go away. If the icon is changing, then something else may be mucking with it. I think NSApp has a -setApplicationIcon: method. Put a breakpoint on that and see who else calls it. – bbum Oct 03 '15 at 16:53
  • Thanks @bbum ill investigate! – Noitidart Oct 03 '15 at 20:27

0 Answers0