NSString副本不复制? [英] NSString copy not copying?

查看:68
本文介绍了NSString副本不复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  NSString *myString = @"sample string";
  NSString *newString = [myString copy];

如果我在这两行之后设置断点,myString的指针与指针的指针相同newString。

If I set a breakpoint after these two lines, the pointer for myString is the same as the pointer for newString.

WTF?是不是NSString副本应该返回一个指向新对象的指针?或者我错过了关于副本应该如何工作的基本原因?

WTF? Isn't NSString copy supposed to return a pointer to a new object? Or am I missing something fundamental about how copy is supposed to work?

推荐答案

因为 NSString 不可变它可能只是内部增加参考计数并完成它。

Since NSString is not mutable it might just internally increase ref count and be done with it.

当你发布其中一个NSStrings时,它可能只会减少 ref count - 标准内存管理。

When you release one of those NSStrings it might just decrement ref count - standard memory management.

你认为有什么问题吗?

这篇关于NSString副本不复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆