I'm new to swift.I'm running instrument tool for memory leaks.I found a leak "_ContiguousArrayStorage<String>"
Its leading to below part of the code
let myData = NSData(data: request.value!)
let buffer = Array(UnsafeBufferPointer(start: UnsafePointer<CUnsignedChar>(myData.bytes), count: myData.length))
Can anyone help me out?.
Anything wrong with above code?
Edit: Adding some more code.
let myData = NSData(data: request.value!)
var buffer = Array(UnsafeBufferPointer(start: UnsafePointer<CUnsignedChar>(myData.bytes), count: myData.length))
let responseArray: [CUnsignedChar] = Array(buffer)
let responseValue = BluetoothCommunicationManager.sharedInstance.parseData(responseArray,length: myData.length).0
let responseName = BluetoothCommunicationManager.sharedInstance.parseData(responseArray,length: myData.length).1
NSNotificationCenter.defaultCenter().postNotificationName(responseName, object: request, userInfo: responseValue as [NSObject : AnyObject])
The parseData method of the singleton class returns NSMutableDictionary.
func parseData(responseData: [CUnsignedChar]) -> NSMutableDictionary
{
let infoDictionary = NSMutableDictionary()
let subIndexValue = Int(responseData[5])
infoDictionary.setValue(subIndexValue, forKey: KEY_SUB_INDEX)
return responseData
}
Thanks in advance.
Very dangerous. Memory leaks in the kernel level lead to serious system stability issues. Kernel memory is very limited compared to user land memory and should be handled cautiously. Memory is allocated but never freed.
Memory leaks don't result in physical or permanent damage. Since it's a software issue, it will slow down the applications or even your whole system. However, a program taking up a lot of RAM space doesn't always mean its memory is leaking somewhere.
Physical or permanent damage does not happen from memory leaks. Memory leaks are strictly a software issue, causing performance to slow down among applications within a given system. It should be noted a program taking up a lot of RAM space is not an indicator that memory is leaking.
It looks like you are trying to convert the NSData
to an array of CUnsignedChar
. You don't need to use UnsafeBufferPointer
or UnsafePointer
to do that conversion. I suspect your use of the unsafe pointers is the root cause of your memory leak.
You can just create the array by passing it a Data
object instead of an NSData
object. Try this instead:
let myData = NSData(data: request.value!) as Data
let responseArray = [CUnsignedChar](myData)
let responseValue = BluetoothCommunicationManager.sharedInstance.parseData(responseArray, length: responseArray.count).0
let responseName = BluetoothCommunicationManager.sharedInstance.parseData(responseArray, length: responseArray.count).1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With