[swift-users] Memory Leak of Dictionary used in singleton
Joe Groff
jgroff at apple.com
Fri Mar 24 15:48:20 CDT 2017
> On Mar 11, 2017, at 4:04 PM, Ekaterina Belinskaya via swift-users <swift-users at swift.org> wrote:
>
> Hi everyone!
>
> I have singleton. It contains a 2 dictionaries.
>
> struct Stat {
> var statHash:String
> var displayDescription:String
> var displayName:String
> var displayIcon:String
> var statIdentifier:String
> }
>
> class Singleton {
>
> static let sharedInstance = Singleton()
>
> var statsDesc = [String:Stat]()
> var test = [String: String]()
>
> init() {
> test["a"] = "b"
> }
> }
>
> let singlton = Singleton.sharedInstance
> On using the leaks tool, I am getting a memory leak of the second dictionary(String, String).
>
> screenshot of memory graph debugger <http://imgur.com/a/JRcGd>
>
> If i remove dictionaries and write smth like that:
>
> class Singleton {
>
> static let sharedInstance = Singleton()
> var num: Int
>
> init() {
> num = 3
> }
> }
> leak disappears.
>
> Could someone, please, explain why this happens?
>
>
This sounds a lot like:
https://bugs.swift.org/browse/SR-3661 <https://bugs.swift.org/browse/SR-3661> Memory Leak from Multiple Dictionary Properties
which was fixed in Xcode 8.3. What version of the compiler are you using?
-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170324/88dbec41/attachment.html>
More information about the swift-users
mailing list