ios singleton class crashes my app

后端 未结 3 1169
一整个雨季
一整个雨季 2021-01-26 06:18

I have a problem with an singleton pattern.

I have read the following tutorials about singleton classes and have created my own. http://www.galloway.me.uk/utorials/sing

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 07:09

    I'm not sure whether it's the (complete) answer, but one major flaw is that you're using instance variables (self, super) in a class method, +(id)bpManager; I'm actually surprised it let you compile that at all. Change the @synchronized(self) to @synchronized(sharedMyManager), and the [[super alloc...] init] to [[BPManager alloc...] init]. And, writing that just made me realize that the problem looks like accessing a subclassed method on an object instantiated as the superclass, but that should have been overwritten in the dispatch. Shouldn't you really only need one of those anyway, why double-init like that? (And while we're there, that's a memory leak - init'd in the if() and then overwritten in the closure without releasing it.)

提交回复
热议问题