我從下面的代碼中收到一堆內存泄漏......我試圖用一種更好的方式重寫它,但真的想不出別的什麼。建議將不勝感激。以下是消息發送到的對象。內存泄漏類的方法
Packet *packet;
packet = [PacketAudioBuffer packetWithData:data];
PacketAudioBuffer.m文件 - >
+ (id)packetWithData:(NSData *)data
{
int totalSize = [data length];
int packetNumber = [data pm_int32AtOffset:4];
return [[self alloc] initWithAudioBufferData:data totalSize:totalSize packetNumber:packetNumber];
}
- (id)initWithAudioBufferData:(NSData *)data
totalSize:(UInt32)totalSize
packetNumber:(UInt32)packetNumber
{
if ((self = [super initWithType:PacketTypeAudioBuffer]))
{
// this is where audioBufferData is set.
self.audioBufferData = data;
self.totalSize = totalSize;
self.packetNumber = packetNumber;
}
return self;
}
任何調用packetWithData負責釋放結果。 – Dave