我在自定义nsobject上映射xml。
当用户点击重新加载时,再次调用该函数。
我在所有字符串上都有几个内存泄漏:
更新这是当前的代码。
- (void)mapDataOnModel
{
if(mixesArr != nil)
{
//[mixesArr release];
[mixesArr removeAllObjects];
[playListArr removeAllObjects];
}
else
{
mixesArr = [[NSMutableArray alloc]init];
playListArr = [[NSMutableArray alloc] init];
}
MixVO *tmpMix;
AudioVO *tmpAudio;
for (DDXMLElement *node in nodes)
{
tmpMix = [[MixVO alloc] init];
tmpMix.uuid = [[node attributeForName:@"uuid"] stringValue];
tmpMix.name = [[[node elementsForName:@"name"] objectAtIndex:0] stringValue];
tmpMix.artist = [[[node elementsForName:@"artist"] objectAtIndex:0] stringValue];
tmpMix.path = [[[node elementsForName:@"file"] objectAtIndex:0] stringValue];
tmpMix.headline = [[[node elementsForName:@"headline"] objectAtIndex:0] stringValue];
tmpMix.teaser = [[[node elementsForName:@"teaser"] objectAtIndex:0] stringValue];
tmpMix.copy = [[[node elementsForName:@"copy"] objectAtIndex:0] stringValue];
tmpMix.isHighlight = NO;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm:ss"];
tmpMix.duration = [dateFormat dateFromString:[[[node elementsForName:@"duration"] objectAtIndex:0] stringValue]] ;
[dateFormat release];
// CHECK IF IT IS A HIGHLIGHT MIX
for (int i = 0; i < [[highlightsNode elementsForName:@"member"] count]; i++)
{
NSString *highlightID;
highlightID = [[[highlightsNode elementsForName:@"member"] objectAtIndex:i] stringValue] ;
if([tmpMix.uuid isEqualToString:highlightID])
{
tmpMix.isHighlight = YES;
}
}
if([[node elementsForName:@"image_standard"] count] > 0)
tmpMix.image_standard = [[[node elementsForName:@"image_standard"] objectAtIndex:0] stringValue] ;
if([[node elementsForName:@"image_artist"] count] > 0)
tmpMix.image_artist = [[[node elementsForName:@"image_artist"] objectAtIndex:0] stringValue] ;
if([[node elementsForName:@"image_teaser"] count] > 0)
tmpMix.image_teaser = [[[node elementsForName:@"image_teaser"] objectAtIndex:0] stringValue] ;
if([[node elementsForName:@"image_player"] count] > 0)
tmpMix.image_player = [[[node elementsForName:@"image_player"] objectAtIndex:0] stringValue] ;
/*
tmpAudio = [[AudioVO alloc] init];
tmpAudio.file = tmpMix.path;
NSString *tmpDuration;
tmpDuration = [[[node elementsForName:@"duration"] objectAtIndex:0] stringValue];
tmpAudio.duration = tmpDuration;
// PARSE TRACKS
NSArray *track = NULL;
track = [node elementsForName:@"tracks"];
DDXMLElement *trackElems = [track objectAtIndex:0];
NSArray *tracks = NULL;
tracks = [trackElems elementsForName:@"track"];
NSMutableArray *tracksArray;
tracksArray = [[NSMutableArray alloc]init];
TrackVO *tmpTrack;
for (DDXMLElement *node2 in tracks)
{
tmpTrack = [[TrackVO alloc] init];
tmpTrack.timecode = [[node2 attributeForName:@"timecode"] stringValue];
tmpTrack.name = [node2 stringValue];
[tracksArray addObject:tmpTrack];
[tmpTrack release];
}
tmpAudio.tracksArr = tracksArray;
[tracksArray release];
tmpMix.audioVO = tmpAudio;
[tmpAudio release];
*/
[mixesArr addObject:tmpMix];
[tmpMix release];
}
// SORT PROGRAMM
/*
NSSortDescriptor *lastDescriptor =
[[[NSSortDescriptor alloc]
initWithKey:@"artist"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];
NSArray * descriptors =
[NSArray arrayWithObjects:lastDescriptor, nil];
NSArray * sortedArray = [mixesArr sortedArrayUsingDescriptors:descriptors];
//[mixesArr release];
mixesArr = [[NSMutableArray alloc]initWithArray:sortedArray];
// PARSE PLAYLIST
for (DDXMLElement *node in nodesPl)
{
SchedVO *tmpSched;
tmpSched = [[SchedVO alloc] init];
NSString *timeStr;
timeStr = [[node attributeForName:@"timestamp"] stringValue];
tmpSched.date = [NSDate dateWithTimeIntervalSince1970:timeStr.intValue];
tmpSched.uid = [node stringValue];
[playListArr addObject:tmpSched];
//[tmpSched release];
}
*/
[self updateDone];
}
MixVO:
@interface MixVO : NSObject
{
NSString *uuid;
NSString *name;
NSString *artist;
NSString *path;
NSString *headline;
NSString *teaser;
NSString *copy;
NSString *image_standard;
NSString *image_artist;
NSString *image_teaser;
NSString *image_player;
NSDate *duration;
AudioVO *audioVO;
BOOL isHighlight;
}
@property (nonatomic,retain) NSString *uuid;
@property (nonatomic,retain) NSString *name;
@property (nonatomic,retain) NSString *artist;
@property (nonatomic,retain) NSString *path;
@property (nonatomic,retain) NSString *headline;
@property (nonatomic,retain) NSString *teaser;
@property (nonatomic,retain) NSString *copy;
@property (nonatomic,retain) NSString *image_standard;
@property (nonatomic,retain) NSString *image_artist;
@property (nonatomic,retain) NSString *image_teaser;
@property (nonatomic,retain) NSString *image_player;
@property (nonatomic,retain) NSDate *duration;
@property (nonatomic,retain) AudioVO *audioVO;
@property BOOL isHighlight;
@end
也许有人可以帮我解决这个问题。
提前谢谢 亚历答案 0 :(得分:1)
if(mixesArr != nil)
{
[mixesArr removeAllObjects];
[playListArr removeAllObjects];
}
mixesArr = [[NSMutableArray alloc]init];
这表明mixesArr已经可以分配了,你只需要分配一个新实例,使原来的mixesArr成为一个悬空指针。
你不应该这样写:
if(mixesArr != nil)
{
[mixesArr removeAllObjects];
[playListArr removeAllObjects];
}
else {
mixesArr = [[NSMutableArray alloc]init];
}
或类似的东西?
答案 1 :(得分:0)
你在哪里发布mixesArr?
您还需要释放您保留的所有字符串。