what is difference between alloc and allocWithZone:?

前端 未结 6 1039
逝去的感伤
逝去的感伤 2020-12-12 15:07

From forum discussion , seem like that the big difference is performance factor, allocWithZone: will alloc memory from particular memory area, which reduce cost of swapping.

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 15:41

    Even if the Apple's Documentation indicates that allocWithZone:

    exists for historical reasons; memory zones are no longer used by Objective-C. You should not override this method.

    and

    Zones are ignored on iOS and 64-bit runtime on OS X. You should not use zones in current development.

    in reality I overridden it in an Objective-C class (in a full Objective-C project) and the method is called when I do [[Mylass alloc] init] even if the build is running on an iPhone 6s.

    But I think it's better to follow the documentation and override alloc method instead of this one because alloc can certainly do the same job.

提交回复
热议问题