-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix autorelease pool emptying when new references are added (#218)
* Add test for emptying autorelease pool * Fix arc autorelease pool emptying when adding further references When releasing a reference in the arc autorelease pool, it is possible and anticipated that new references may added to the pool. This fix addresses an edge case where releasing a reference in the same pool page as the stop position can add more references which cause the insertion of a new page and emptyPool() returns early after emptying the new page.
- Loading branch information
Showing
3 changed files
with
56 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "Test.h" | ||
|
||
#define POOL_SIZE (4096 / sizeof(void*)) | ||
|
||
static BOOL called; | ||
|
||
@interface Canary : Test | ||
@end | ||
@implementation Canary | ||
- (void)dealloc | ||
{ | ||
called = YES; | ||
[super dealloc]; | ||
} | ||
@end | ||
|
||
@interface Creator : Test | ||
@end | ||
@implementation Creator | ||
- (void)dealloc | ||
{ | ||
// Add a new page of autorelease references to see if we can still release | ||
// the reference on the canary object. | ||
for (int i = 0; i < POOL_SIZE; i++) | ||
[[Test new] autorelease]; | ||
[super dealloc]; | ||
} | ||
@end | ||
|
||
int main() | ||
{ | ||
called = NO; | ||
@autoreleasepool | ||
{ | ||
[[Canary new] autorelease]; | ||
[[Creator new] autorelease]; | ||
} | ||
assert(called == YES); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters