• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I don't understand why this is leaking...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I don't understand why this is leaking...


  • Subject: Re: I don't understand why this is leaking...
  • From: Negm-Awad Amin <email@hidden>
  • Date: Tue, 12 Aug 2008 14:17:32 +0200


Am Di,12.08.2008 um 14:11 schrieb Gerriet M. Denkmann:


On 12 Aug 2008, at 18:26, Negm-Awad Amin wrote:

Probably $null is a reserved word. -encodeWithCoder: (NSString) and -initWithCoder: (NSString) should escape that. No good …

Wenn es das wäre, dann hätte man das sicherlich documentiert.
(This as a challenge for our English-speaking (or should one say: "germanilly challenged" ?) list-members).
The challenglish continues :-)

Ich denke, dass man das einfach nicht bedacht hat. Vom Standpunkt von NSString existiert dieses Problem ja nicht. Erst in Verbindung mit dem Coder wird dieser das anders interpretieren.

Aber gut, dass es gefixt ist. So etwas kann einen ja in den Wahnsinn treiben.




Herzliche Grüße aus Bangkok
Liebe Grüße


Amin



Gerriet.


A: Yes. | Q: Are you sure? | | A: Because it reverses the logical flow of conversation. | | | Q: Why is top posting frowned upon?



Amin

Am Di,12.08.2008 um 12:25 schrieb Gerriet M. Denkmann:


On 12 Aug 2008, at 15:50, Negm-Awad Amin wrote:

Am Di,12.08.2008 um 10:42 schrieb Gerriet M. Denkmann:

On 9 Aug 2008, at 17:39:20 -0600, Jonathan deWerd <email@hidden >wrote:

On Aug 9, 2008, at 4:48 PM, Cate Tony wrote:
[...]

Also, why are you using non-keyed encoding? - encodeObject:forKey: is
the preferred way of doing things nowadays...

Well, it may be the preferred way, but it is not always the best, nor even the correct way.


Two reasons:
1. the resulting files are much bigger
2. NSKeyedArchiver can only store certain strings (tested in 10.4.11), which makes it absolutely unusable for the storage of strings if the possible values are not known in advance.
Do you have an example for that?

Yes, I have.

1. Simple Test:
In IB create new window, add NSTextField with content "$null" (without the quotes) save in 10.2 or later format. Close. Open again. Look at your string.


2. A whole new project:

------------- main.m --------------
#import <Foundation/Foundation.h>
#import "TwoStrings.h"

int main (int argc, const char * argv[])
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *s1 = @"$null"; // NSKeyedArchiver cannot handle this - last tested 10.4.11
NSString *s2 = @"$Null";

TwoStrings *to = [ [ TwoStrings alloc ] initWith: s1 and: s2 ];
NSLog(@" original: %@", to);

NSData *dataA = [ NSArchiver archivedDataWithRootObject: to ];
TwoStrings *ta = [ NSUnarchiver unarchiveObjectWithData: dataA ];
NSLog(@" Archiver: %@ %3u bytes", ta, [ dataA length ]);


NSData *dataK = [ NSKeyedArchiver archivedDataWithRootObject: to ];
TwoStrings *tk = [ NSKeyedUnarchiver unarchiveObjectWithData: dataK ];
NSLog(@" KeyedArchiver: %@ %3u bytes", tk, [ dataK length ]);

[pool release];
return 0;
}



------------- TwoStrings.h -------------- @interface TwoStrings : NSObject { NSString *s1; NSString *s2; }

- initWith:(NSString *)sender and: (NSString *)s ;

@end


------------- TwoStrings.m -------------- #import "TwoStrings.h"

@implementation TwoStrings

- initWith:(NSString *)sender and: (NSString *)s ;
{
	self = [ super init ];
	if ( self == nil ) return nil;
	s1 = [ sender retain ];
	s2 = [ s retain ];
	return self;
}

- (void)dealloc
{
	[ s1 release ];
	[ s2 release ];
	[ super dealloc ];
}

- (NSString *)description
{
NSString *s = [ NSString stringWithFormat: @"<%@ %p s1=\"%@\" s1= \"%@\">",[ self class], self, s1, s2 ];
return s;
}


- (void)encodeWithCoder:(NSCoder *)coder
{
//[super encodeWithCoder:coder]; // not for direct subclasses of NSObject

if ( [coder allowsKeyedCoding] )
{
[ coder encodeObject: s1 forKey: @"s1" ];
[ coder encodeObject: s2 forKey: @"s2" ];
}
else
{
[ coder encodeObject: s1 ];
[ coder encodeObject: s2 ];
};
}


- (id)initWithCoder:(NSCoder *)decoder
{
//self = [super initWithCoder:decoder]; // not for direct subclasses of NSObject

if ( [decoder allowsKeyedCoding] )
{
s1 = [ decoder decodeObjectForKey: @"s1" ];
s2 = [ decoder decodeObjectForKey: @"s2" ];
}
else
{
s1 = [ decoder decodeObject ];
s2 = [ decoder decodeObject ];
};

[ s1 retain ];
[ s2 retain ];

return self;
}


@end

------------- End of project --------------

Maybe this will work on Leopard. On Tiger it does not. (No crash, nor error message either).


Kind regards,

Gerriet.

Amin Negm-Awad email@hidden






Amin Negm-Awad email@hidden




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: I don't understand why this is leaking... (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: I don't understand why this is leaking... (From: Negm-Awad Amin <email@hidden>)
 >Re: I don't understand why this is leaking... (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: I don't understand why this is leaking... (From: Negm-Awad Amin <email@hidden>)
 >Re: I don't understand why this is leaking... (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: I don't understand why this is leaking...
  • Next by Date: Create a calendar group using CalendarStore framework
  • Previous by thread: Re: I don't understand why this is leaking...
  • Next by thread: Re: I don't understand why this is leaking...
  • Index(es):
    • Date
    • Thread