问题描述
在Objective-C中,简单地讲-我在假设
in Objective-C and simply speaking - am I correct when assuming
- 正确时,必须正确释放所有指针变量时是否正确?
- 每个指针变量(*)是某种类吗?
- 每个指针变量因此都需要分配并使用分配和初始化(或类似方法)初始化?
- 使用对象方法声明变量时,我可能不需要分配或初始化吗?
- 数字声明(BOOL,int,float等)只要不声明为指针就不需要内存管理?
- that all pointer variables must be released when they're not used any more?
- Every pointer variable (*) is a class of some kind, or not?
- Every pointer variable therefore needs to be allocated and initialised using "alloc" and "init" (or similar)?
- When declaring variales using Object methods I may not need "alloc" or "init"?
- Number declarations (BOOL, int, float, etc) do not require memory management as long as they're not declared as a pointer?
感谢您提供任何有助于解决我的困惑的建议
iFloh
Thanks for any advice helping to sort out my confusion iFloh
推荐答案
这取决于您是否拥有了所指的东西。我建议您仔细阅读这些内存管理了解如何释放指针的规则。
It depends if you "own" the pointed thing. I recommend you to carefully read these Memory Management rules to learn how to release a pointer.
不是每个指针都可以。指针变量可以保存指向对象或内存块的指针。
Not every pointers. A pointer variable may hold a pointer to an object or to a block of memory. It is just a pointer to something.
不是每个指针都可以。指针变量可以保存指向对象或内存块的指针。指向的对象可以是已经存在的对象,也可以是已分配的内存块。
Not every pointers. A pointer variable may hold a pointer to an object or to a block of memory. The pointed thing can be an already existing object or an allocated chunck of memory.
不是每次都这样。您可能会得到一个指向现有对象的指针,而不知道是谁分配和初始化了它。同样,要遵循一些所有权规则。我建议您仔细阅读这些内存管理
Not everytime. You may get a pointer to an existent object without knowing who allocated and initialized it. Again, there are some ownership rules to follow. I recommend you to carefully read these Memory Management rules.
是。有所谓的原始类型,只要您将它们作为值来操纵,就不必处理它们的内存管理。
Yes. There are called primitive types, and as long as you manipulate them as value, you don't have to deal with their memory management.
这篇关于我要分配/释放哪些对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!