2011-02-10 7 views
0

私は数日間のようにこのエラーをデバッグしようとしていますが、本当に私のオブジェクトで起こっているものを把握しているように見えません。 コードは次のようになります。 - (BOOL)のWebView:(のUIWebView *)のWebView shouldStartLoadWithRequest:(NSURLRequest *)要求navigationType:クリックしたリンクから(UIWebViewNavigationType)navigationType { //抽出データ私のカスタムクラスオブジェクトは、それを保持した後でも解放されます

SongObject *データ= [[SongObject ALLOC] INIT]。 [データ保持]; selectedSong =データ。 }

selectedSongはメインクラスのパブリック変数ですが、今は奇妙なことですが、上記のメソッドを使用することは、他の場所でもshoulStartLoadWithRequestでも機能します。

私は「範囲外です」と言いますが、「shouldStartLoadWithRequest」が私のオブジェクトをオートレースしているという狂った理由がありますか?

アイデアはありますか?

編集:これは、selectedSongが保持すると思われるHおよびMファイルです。

#import <Foundation/Foundation.h> 
#import "SongObject.h" 


@interface SongObject : NSObject<NSCopying> { 
    NSString *artist; 
    NSString *titel; 
    NSString *album; 
    NSString *genre; 
    NSString *songUrl; 
    NSString *rating; 
    NSString *image; 
    BOOL  local; 
} 
@property (readonly) NSString *getArtist; 
@property (readonly) NSString *getTitle; 
@property (readonly) NSString *getAlbum; 
@property (readonly) NSString *getGenre; 
@property (readonly) NSString *getSongURL; 
@property (readonly) NSString *getRating; 
@property (readonly) NSString *getImage; 
@property (readonly) BOOL  isLocal; 



-(void) setInfo:(NSString *) a: (NSString*) t: (NSString*) ab: (NSString*)g: (NSString*)sU: (NSString*)r: (NSString*) i: (BOOL) loc; 
@end 



#import "SongObject.h" 


@implementation SongObject 
-(id)init 
{ 
    if(self =[super init]) 
    { 
     NSLog(@"Init songobject"); 
    } 
    return self; 
} 
-(id) copyWithZone: (NSZone *) zone { 
    SongObject *newSong = [[SongObject allocWithZone:zone] init]; 
    NSLog(@"_copy: %@", [newSong self]); 
    [newSong setInfo:[self getArtist] :[self getTitle] :[self getAlbum] :[self getGenre] :[self getSongURL] :[self getRating] :[self getImage] :[self isLocal]]; 
    return(newSong); 
} 


-(void)dealloc 
{ 
    NSLog(@"Songobject deallocted from memory..."); 
    [super dealloc]; 
} 
-(void) setInfo:(NSString *) a: (NSString*) t: (NSString*) ab: (NSString*)g: (NSString*)sU: (NSString*)r: (NSString*) i: (BOOL) loc{ 
    artist = a; 
    titel = t; 
    album = ab; 
    genre = g; 
    songUrl = sU; 
    rating = r; 
    image = i; 
    local = loc; 
} 

-(NSString*)getArtist 
{ 
    return artist; 
} 

-(NSString*)getTitle 
{ 
    return titel; 
} 

-(NSString*)getAlbum 
{ 
    return album; 
} 

-(NSString*)getGenre 
{ 
    return genre; 
} 

-(NSString*)getSongURL 
{ 
    return songUrl; 
} 

-(NSString*)getRating 
{ 
    return rating; 
} 

-(NSString*)getImage 
{ 
    return image; 
} 
-(BOOL)isLocal{ 
    return local; 
} 

@end 

答えて

0

最後にNSString変数を持つSongObjectクラスが保持されないという問題が見つかりました。したがってselectedSongは実際にはリリースされませんでしたが、クラス内の変数はそれ自身です。 NSString alloc initWithStringを使用し、deallocメソッドをオーバーライドしてそこで解放することで修正しました。

0

これは可能ではないようです。参照カウントを2倍に増やしているので、注意してください。一度はallocで、もう一度retainで再び。 selectedSongはどのように見えますか?それは自動化された保持を持つプロパティですか?

また、デバッガでオブジェクトを読み取ることができず、NSLogを使用することがあります。あなたはそれから何を見ますか?

-deallocのオーバーライドはどうですか。そこにブレークポイントを設定しようとしましたか?

+0

これはselectedSongが保持すべきクラスファイルです。 –

+0

また、NSLog(@ "Artist:"、[selectedSong getArtist])のようにNSLogを使用する場合は、何も返しません。 –

関連する問題