Sag*_*ari 1 xcode global-variables objective-c cocos2d-iphone
我已经完成了以下问题.
但问题与静态变量有关.它有一些不同的情况,然后我的.
我在应用程序中有以下代码.
//.h file
#import "cocos2d.h"
#import "something.h"
#import "myLayer.h"
#import "LayerData.h"
// i have taken this variables as global
// because two different classes are simultaneously accessing it
myLayer *myCurrentLayer;
LayerData *boxLayerData[10][12];
@interface one
// my class definition here
@end
@interface two
// my second class definition here
@end
//------------------------------------------------
@implementation one
// my class constructor here.
-(id)init{
myCurrentLayer=[[myLayer alloc] init];
// boxLayerData is initialized with objects
}
@end
@implementation two
// second class constructor
-(id)init{
[myCurrentLayer setPosition:ccp(10,20)];
[self schedule something for movements];
}
@end
//------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
好.我的困惑是"如何释放120大小的"LayerData*boxLayerData [10] [12];"数组?"
同样的答案适用于全局,因为它适用于静态.如果您需要整个应用程序生命周期的数据,请保持原样,并在应用程序终止时由操作系统回收内存.如果需要在应用程序执行期间释放对象,则可以遍历数组并在每个对象上调用release.
像这样的东西:
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
LayerData *data = boxLayerData[i][j];
[data release], data = nil;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2073 次 |
| 最近记录: |