diff --git a/Examples/textcoding.m b/Examples/textcoding.m index db2c9c034..b283f0bc5 100644 --- a/Examples/textcoding.m +++ b/Examples/textcoding.m @@ -5,17 +5,22 @@ */ #include +#include #include #include #include #include #include +#include int main() { id set, ll; id coder; id name; + id arp; + + arp = [[NSAutoreleasePool alloc] init]; /* Create a Set of int's and a LinkedList of float's */ @@ -41,7 +46,9 @@ int main() [ll printForDebugger]; /* Write them to a file */ - coder = [Coder coderWritingToFile: @"./textcoding.txt"]; + + coder = [[Coder alloc] initForWritingToFile: @"./textcoding.txt" + withCStreamClass: [TextCStream class]]; [coder encodeObject:set withName:@"Test Set"]; [coder encodeObject:ll withName:@"Test EltNodeCollector LinkedList"]; @@ -49,7 +56,16 @@ int main() [set release]; [ll release]; + /* Close the coder, (and thus flush the stream); then release it. + We must separate the idea of "closing" a stream and + "deallocating" a stream because of delays in deallocation due to + -autorelease. */ + [coder closeCoder]; + [coder release]; + + /* Read them back in from the file */ + /* First init the stream and coder */ coder = [Coder coderReadingFromFile: @"./textcoding.txt"]; @@ -68,6 +84,9 @@ int main() /* Relase the objects we read */ [set release]; [ll release]; + + /* Do the autorelease. */ + [arp release]; exit(0); }