Swapping the `objectAtIndex:` method of `__NSArrayM` using `method_exchangeImplementations` will lead to continuous memory growth.

After swapping the -objectAtIndex: method using method_exchangeImplementations, it will cause continuous memory growth.

  1. Connect the iPhone and run the provided project.
  2. Continuously tap the iPhone screen.
  3. Observe Memory; it will keep growing.

Sample code

Answered by DTS Engineer in 848205022

What you’re doing is deeply unsupported, and I strongly recommend that you stop doing it.

In general, Apple doesn’t support folks swizzling methods on Apple’s classes. And in this case you’re swizzling methods on a class, __NSArrayM, that’s an implementation detail. It’s never good to rely on implementation details because they could change at any time, and that would break your code.

If you explain more about your high-level goal, I may be able to suggest an alternative path forward.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What you’re doing is deeply unsupported, and I strongly recommend that you stop doing it.

In general, Apple doesn’t support folks swizzling methods on Apple’s classes. And in this case you’re swizzling methods on a class, __NSArrayM, that’s an implementation detail. It’s never good to rely on implementation details because they could change at any time, and that would break your code.

If you explain more about your high-level goal, I may be able to suggest an alternative path forward.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Swapping the `objectAtIndex:` method of `__NSArrayM` using `method_exchangeImplementations` will lead to continuous memory growth.
 
 
Q