Hi,
Doing some tests I have bumped into what could be a bug in Swift 2 and XCode 7 (beta 5). It doesn't happend in Swift 1 and XCode 6.4.
It is related with memory not released if I cast NSDictionay as [String:AnyObject] in a "switch" statemen.
By the way, is something that happends in "SwiftyJSON" utility library. Quite common to access JSON objects.
I had something like this:
//-------------------------------------------------------------------------------------------
let pathName = "my_json_data_file.json"
// Big loop to see how memory grows
for var n=0;n<20000;n++ {
// Autorelease pool to release objects a soon as possible and avoid confusing the memory leak with that
autoreleasepool {
do {
let jsonData = try NSData(contentsOfFile: pathName, options: NSDataReadingOptions())
let value: AnyObject = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments)
// This is the problematic code
switch value {
case _ as [String : AnyObject]:
// Something to do
break
default:
// Somethig...else
break
}
} catch {
print("error!")
}
}
}
But if I change the "switch" part with any of the followings the memory doesn't grow.
if value is [String:AnyObject] {
// Do something
} else {
// ... else
}
if let _ = value as? [String:AnyObject] {
// Do something
} else {
// ... else
}
Is it a bug? Am I doing something wrong?
Thanks