1

I'm developing an app using the Singleton Pattern and Swift programming language. When I Profile the app with Instruments, I noticed that there's a memory leak pointing to an NSArray. Instruments is pointing to the following line of code (Please check screenshot). Can anyone find why the leak is happening? I tried to initialize the array Workout as:

workout = []

The leak wasn't reported. Maybe it has something to do with the unarchiving? enter image description here enter image description here

HusseinB
  • 1,321
  • 1
  • 17
  • 41
  • You should check this: http://stackoverflow.com/questions/24024549/dispatch-once-singleton-model-in-swift in order for the correct singleton pattern in Swift. – Dániel Nagy Sep 21 '15 at 09:58

1 Answers1

0

Checkout this answer here: Swift Decode Array Custom Class Memory Leak It seems to be a bug. I had the same problem too. So instead of directly assign the value to workout, you can do:

if let wo = NSKeyedUnarchiver.unarchiveObjectWithFile(Utilities.getFileURL("workout")) as? [ExceciseObject] {
    workout = wo.map { $0 }
}
Community
  • 1
  • 1
Zhao
  • 904
  • 1
  • 11
  • 34