处理枚举时是否必须注意内存?
这是我声明枚举类型的地方。它在另一个 .h 文件中
这是我尝试声明变量的地方
之后我要不要做类似的事情
// This is where I declared my enum type. It is in another .h file
typedef enum CardTypes
{
HEART = 1,
DIAMOND =2,
CLUB =3,
SPADE = 4
} CardType;
// This is where I attempt to declare variable
CardType cardType=SPADE;
//or
CardType cardType=malloc(size(CardType));
// After that Do I have o do something like that
[cardType release]
//or
free(&card)
Any help will be appreciated , thanks
最佳答案
这只是一个基本的 C 类型 - 在这方面它的处理方式与 int
类似。
这是自动的:
CardType cardType=SPADE;
但是当您发现必须使用malloc
时,那么您需要释放
它。
通常(例如参数、ivar、局部变量),您可以按值声明枚举,但是(如 int
)您偶尔可能需要使用 malloc
+免费
。
关于objective-c - Objective C typedef Enum 内存管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10772884/