1/* 2 * Copyright (c) 2009 Apple Inc. All rights reserved. 3 * 4 * @APPLE_APACHE_LICENSE_HEADER_START@ 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * @APPLE_APACHE_LICENSE_HEADER_END@ 19 */ 20#import <Foundation/Foundation.h> 21#import <pthread.h> 22#import <objc/objc-auto.h> 23#import "auto_zone.h" 24 25// CONFIG GC -C99 -lauto 26 27int Counter = 0; 28 29@interface TestObject : NSObject { 30 TestObject *link; 31} 32@property(retain) TestObject *link; 33@end 34@implementation TestObject 35@synthesize link; 36- (void)finalize { 37 ++Counter; 38 //printf("finalizing %p\n", self); 39 [super finalize]; 40} 41@end 42 43int howmany = 200000; 44 45void *doOnPthread(void *unused) { 46 objc_registerThreadWithCollector(); 47 for (int i = 0; i < howmany; ++i) { 48 [[TestObject alloc] init]; 49 } 50 return NULL; 51} 52 53 54int main(int argc, char *argv[]) { 55 objc_startCollectorThread(); 56 pthread_t thread; 57 pthread_create(&thread, NULL, doOnPthread, NULL); 58 pthread_join(thread, NULL); 59 auto_collect(auto_zone(), AUTO_COLLECT_FULL_COLLECTION|AUTO_COLLECT_SYNCHRONOUS, NULL); 60 if (Counter*2 < howmany) { 61 printf("recovered %d of %d local thread only objects\n", Counter, howmany); 62 return 1; 63 } 64 printf("%s: Success\n", argv[0]); 65 return 0; 66} 67