iphone - UIColor leaking… need to release the object?

后端 未结 3 1418
日久生厌
日久生厌 2020-12-18 05:46

I have a bunch of lines like this on my app

UIColor *myColor = [UIColor colorWithRed:corR green:corG blue:corB alpha:1.0];

Instruments are

相关标签:
3条回答
  • 2020-12-18 06:16

    Don't release the object, you don't own it and you will eventually get crashes. UIColor is probably just caching these colors for you, and Instruments has no way of knowing this so it reports them as leaks (basically stuff that got created and you don't have a reference to anymore but hasn't been deallocated).

    Try running instruments for some time (using the simulator) and then sending a memory warning to see if UIColor will purge its cache. Either way, there isn't anything you can really do to fix leaks happening inside core frameworks, so don't try. Just make sure you're not actually leaking them somehow (like retaining them at some point and never releasing them).

    0 讨论(0)
  • 2020-12-18 06:24

    If that's all you are doing, myColor is most definitely not leaking. If you are retaining that object anywhere else without releasing it, it is leaking.

    Never release an object that you don't remember retaining. Evvarrrrrrrrr. But I suspect that you just are retaining it somewhere, and don't even notice it.

    0 讨论(0)
  • 2020-12-18 06:35

    Sometimes the simulator can report leaks when there are none, make sure to also see if you get the same leak on the device as well...

    But since it's faster to work with the simulator, try finding things there first.

    0 讨论(0)
提交回复
热议问题