我要分配/释放哪些对象 [英] What objects do I alloc/release

查看:82
本文介绍了我要分配/释放哪些对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中,简单地讲-我在假设

in Objective-C and simply speaking - am I correct when assuming


  1. 正确时,必须正确释放所有指针变量时是否正确?

  2. 每个指针变量(*)是某种类吗?

  3. 每个指针变量因此都需要分配并使用分配和初始化(或类似方法)初始化?

  4. 使用对象方法声明变量时,我可能不需要分配或初始化吗?

  5. 数字声明(BOOL,int,float等)只要不声明为指针就不需要内存管理?

  1. that all pointer variables must be released when they're not used any more?
  2. Every pointer variable (*) is a class of some kind, or not?
  3. Every pointer variable therefore needs to be allocated and initialised using "alloc" and "init" (or similar)?
  4. When declaring variales using Object methods I may not need "alloc" or "init"?
  5. 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

推荐答案


1)所有指针变量在不使用
时必须释放
吗?

1) that all pointer variables must be released when they're not used any more?

这取决于您是否拥有了所指的东西。我建议您仔细阅读这些内存管理了解如何释放指针的规则。

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.


2)每个指针变量(*)都是某类

2) Every pointer variable (*) is a class of some kind, or not?

不是每个指针都可以。指针变量可以保存指向对象或内存块的指针。

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.


3)因此,每个指针变量都需要
进行分配并使用$ b $进行初始化。 b分配和初始化(或类似)?

3) Every pointer variable therefore needs to be allocated and initialised using "alloc" and "init" (or similar)?

不是每个指针都可以。指针变量可以保存指向对象或内存块的指针。指向的对象可以是已经存在的对象,也可以是已分配的内存块。

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.


4)使用Object
方法声明变量时我可能不需要 alloc或
init吗?

4) When declaring variales using Object methods I may not need "alloc" or "init"?

不是每次都这样。您可能会得到一个指向现有对象的指针,而不知道是谁分配和初始化了它。同样,要遵循一些所有权规则。我建议您仔细阅读这些内存管理

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.


5)数字声明(BOOL,int,float,
等)不需要内存管理
,只要未将它们声明为
指针?

5) Number declarations (BOOL, int, float, etc) do not require memory management as long as they're not declared as a pointer?

是。有所谓的原始类型,只要您将它们作为值来操纵,就不必处理它们的内存管理。

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.

这篇关于我要分配/释放哪些对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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