問題タブ [autorelease]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
5 に答える
1413 参照

iphone - iPhone: 自動解放されたオブジェクトのメモリ リーク?

XMLElement オブジェクトの配列を含む XMLParser クラスを使用しています。XMLElement は autorelease 操作を使用して割り当てられています。ただし、何らかの理由で、この行で (instruments を使用して) メモリ リークが発生しています。

また、呼び出し元クラスで XMLParser オブジェクトを解放しています。以下の XMLParser ソース コードの「問題のある」行をコメントとして強調表示しました。

私は本当にそれを修正するためにあらゆることを試みましたが、残念ながら、なぜこれが起こっているのかまったくわかりません. どんな助けでも大歓迎です!

どうもありがとうございました!

0 投票する
4 に答える
231 参照

iphone - Objective C、メモリ管理

1) 保持を使用する理由は何ですか?

たとえば、setter メソッドでは次のようになります。

2) autorelease-Method: 古いオブジェクトを削除するか、新しいオブジェクトを準備しますか?

3) 入力オブジェクトで保持メソッドが呼び出されるのはなぜですか?

だろう

間違っていますか?なぜ?

0 投票する
2 に答える
690 参照

objective-c - NSArrayから返された自動解放オブジェクト?

ランダムなインデックスからオブジェクトを返すメッセージNSArrayを含めるカテゴリを作成しています(Pythonの選択に似ています)。-objectAtRandom

このオブジェクトを返す前に自動解放する必要がありますか?すべきではないと思いますが、よくわかりません...

0 投票する
1 に答える
290 参照

cocoa - appkitアプリケーションのプールの自動解放

自動リリースプールがAppKitアプリで作成およびリリースされるタイミングを正確に理解するのに苦労しています。

たとえば、initをオーバーライドするApplicationControllerクラスがある場合、開始前に作成され、終了後にドレインされる自動解放プールはありますか?

0 投票する
2 に答える
789 参照

objective-c - 自動リリースを使用する場合、実際にリリースされるのはいつですか。

時々、何かが自動リリースされるのだろうかと思います。さまざまなオブジェクトのdeallocにNSLogを追加しましたが、有用なものが見つかりませんでした。

自動リリースを使用すると、いつ何かがリリースされますか?予測できないのでしょうか、それとも余分なスレッドが実行されているのでしょうか。ありがとう。

0 投票する
1 に答える
2191 参照

objective-c - 自動リリースとリリース

一時的に使用する配列が必要な場合、これらの違いは何ですか。

1:

2:

3:

短いので2番が好きです。1番または3番を使用する正当な理由はありますか?

0 投票する
1 に答える
480 参照

iphone - I have to retain a NSMutableArray although it's a property

I'm new, but I read a lot about memory management, and really tried to find the answer myself. It sounds so basic and yet I apparently don't get it. I have a NSMutableArray as property in .h:

I synthesize it and release it in (void) dealloc. To populate the array, I have a method - (void)updateRecordList and in there:

EDIT:next line:

where DocumentDatabase is a different class with the class methods getDocumentListSortedByDate and getDocumentList. Here is what is happening in getDocumentListSortedByDate:

and in getDocumentList

This works the first time I call updateRecordList, but after adding a file and calling updateRecordList a second time, it crashes with (using NSZombies): * -[NSCFNumber dealloc]: message sent to deallocated instance 0x7504c90. With a lot of logging I narrowed the problem down to the line above in updateRecordList and it works if I change it to:

My conclusion is that the array down in getDocumentList has been autoreleased before it arrives. So my questions are:
1. Why do I have to retain it there? Shouldn't that happen by itself by declaring the property (retain)? Or, in other words, why is the array autoreleased too early (assuming this is what is happening)?
2. When I assign a new array to self.documentListArray, is the old array automatically released? If I try to release it myself before getting a new documentList, it crashes too.

Thanks in advance for any reply.

EDIT: Maybe I'm an idiot: I failed to mention that documentListArray is the data source for an UITableView (see the added line on top). I suspect that I am doing something wrong with populating the table view, and the array gets retained...? It does however crash on assigning the property, not on reloadData. I go back to study if I use the UITableViewDataSource protocol properly. Thanks to everybody, your answers brought me hopefully on the right track. Will update when solved.

EDIT2: It works now without retaining, and I think I understand why: I debugged extensively and found that Objects contained in Objects added to the array where nil. Particularly, deep down in encodeWithCoder I did not use "self" when assigning values. When decoding, those values where nil. Since I changed that, it seems to work. I suspect that not assigning the new array caused the crash, but the TableView which would read the new array-even before I call reloadData. Which would lead back to Davids question of synchroneous access. Thank you all for your help.

0 投票する
1 に答える
268 参照

objective-c - 安全な NSArray アクセス

使用するために保持され自動解放されたオブジェクトを返すことを期待objectAtIndex:していましたが、自動解放プールを使用したテストでは、そうではないことが示されました。

この場合、 objectAtIndex を使用して参照を取得した、その参照を使用または保持するに、別のスレッドが配列からオブジェクトを削除するのを防ぐにはどうすればよいでしょうか?

0 投票する
2 に答える
182 参照

iphone - IPhone のメモリ管理 (自動解放) の明確化

ここで以前に同様の質問が回答されたことは知っていますが、もう少しよく理解したいと思います。これが私のシナリオです...

以下に示すように、割り当てられた UIImageView を返すヘルパー クラス メソッドがあります。

}

次に、UIViewController メソッドの 1 つで、それをそのまま使用しています。

私の質問は、この記憶がどのように解放されるかに関するものです。私は自動解放プール (アプリケーションが作成したもの以外) を使用しておらず、変数は iVar/Property ではありません (そのため、dealloc が呼び出されても解放されません)。この場合、呼び出した後にメモリを解放する責任がありますか? 自動解放はいつ機能しますか? 助けてくれてありがとう!

0 投票する
3 に答える
3102 参照

objective-c - NSString componentsSeparatedByString:自動解放された配列を返しますか?

次の方法では、配列の1つを解放すると例外が発生する理由がわかりません。私が見ることができた唯一の理由componentsSeparatedByStringは、自動解放された配列を返すかどうかですが、ドキュメントにそれが含まれていると記載されていることはわかりません。

アレイが自動解放されているかどうかを誰かが確認できますか?もしそうなら、どうすれば知ることができますか/なぜ知る必要がありますか?
オブジェクトのいずれかのインスタンスがコードによって自動解放されているかどうかを確認することは可能ですか?