誰も私のためにこれをクリアすることはできますか?
私は、1000と2000文字列の間に何かを表示するはずのTableViewControllerを持つiPadアプリケーションを構築しています。 私はこれらのNSStringをシングルトンに持っています。
シングルトンのinitメソッドでは、すべてのデータを保持する配列を初期化します(最終的な方法である必要はありません)。
私はself.someArray = [[NSArray alloc]initWithObjects:
を実行しました。多数の文字列、それに続くnil。
シミュレータで正常に動作しましたが、アプリケーションの起動時にiPad上で正しくアクセスできずにクラッシュしました
代わりに便利な方法[NSArray arrayWithObjects:
を使用するとうまくいきます。
私はInstrumentsを見て、アプリケーションの全体的なメモリフットプリントはわずか約2,5 MBです。
今、私はそれがなぜ一方的に機能するのか、他のものではないのか分かりません。
EDIT:大規模なNSArray - initWithObjects対ArrayWithObjects
#import "StaticValueContainer.h"`
static StaticValueContainer* instance = nil;
@implementation StaticValueContainer
@synthesize customerRatingKeys;
+(StaticValueContainer*)sharedInstance
{
if (instance == nil){
instance = [[StaticValueContainer alloc]init];
}
return instance;
}
-(id)init
{
if ((self = [super init]))
{
[self initCustomerRatingKeys];
}
return self;
}
-(void)init customerRatingKeys
{
self.customerRatingKeys = [[NSArray alloc]initWithObjects:
@"string1",
....
@"string1245"
,nil
}
私が言ったように:それはself.customerRatingKeys = [[NSArray alloc]initWithObjects:
と、デバイス上でクラッシュしますが* self.customerRatingKeys = [[NSArrayのarrayWithObjectsで動作します... `
はい - これは私が知っている違いです...しかし、これはこのクラッシュにどのように関連しているのか理解できません。おそらく、メモリの観点から何か問題があります。コードを追加しました。多分、それは物事をクリアするのに役立ちます。 – HeikoG
'self.customerRatingKeys = [[NSArray alloc] initWithObjects:' - あなたのプロパティが宣言されていると仮定して(通常はそうである)「保持する」。あなたはどのようにあなたの財産を宣言していますか? – lxt
はい私はそれをretainと宣言します。どんな問題がありますか? – HeikoG