-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NSHashTable weak objects releasing #3
Comments
Interesting! Definitely learned something new. It seems like once you leave the scope of an It might be a better idea for me to create my own container object with Here's a playground that shows the behavior difference when you comment/uncomment the pool: import Foundation
var count = 0
class MyObject: NSObject {
override init() {
super.init()
count += 1
}
deinit {
count -= 1
}
}
let table = NSHashTable<NSObject>.weakObjects()
//autoreleasepool {
var o1: NSObject? = MyObject()
var o2: NSObject? = MyObject()
count
table.add(o1)
table.add(o2)
table.count
table.allObjects
count
//}
count
table.count
table.allObjects
count
table.removeAllObjects()
table.count
table.allObjects
count |
@toohotz if you're interested in contributing to this library, that'd be so helpful! Maybe adding some tests that prove the bug, then we can fix it? |
Would gladly like to as I have an appreciation to when caching just works 😉 So this post turned out a bit different as I decided to poke around and implement just a working version of removing a value from the storage cache and also stopping listeners from observing a model as well. I'll point to my fork that I had where I tested a few things out to make sure the I assume you had intentions to implement the remove at some point and your coding style differs quite a bit from my own of course but I played around while trying to keep consistent to what you already have implemented so far. It's of course no means a fleshed out solution yet as I have not tested the list which is just a collection of Anyhow, if you did have plans and not enough time and this is the direction that you're heading in then we can discuss a bit on cleaning the code up more to how you'd expect it. Things as in the throwing function for removing a value I chose to do so because naturally when calling |
@toohotz definitely open to considering more broad changes to the framework! Though I've found changing too many things at once makes it infinitely more difficult to critically understand fixes/changes. Let's change one thing at a time. If you'd like to submit a PR proposing how to fix this, I'd love to take a look! |
Ahoy there @rnystrom, while sifting through your nice collection of repos, I came across this one which I see is still being worked on and just wanted to comment a bit on this guy below.
FlatCache/FlatCache/FlatCache.swift
Line 71 in 5700835
I recently came across☹️
NSHashTable
andMSMapTable
and found their ideas to be quite useful then I tested it out and found some issues when using weak references within the tables such as the ones found in the link below and a few other placesA quick playground of testing out what others spoke about seems to hold true at least in terms of when the object within the table is released
http://cocoamine.net/blog/2013/12/13/nsmaptable-and-zeroing-weak-references/
Then I got a little curious when I saw your implementation of FlatCache from Soroush and was wondering (if you had freetime of course) to test out the usage of FlatCache and it working as expected? I like the idea that the tables provide the flexibility of using both strong and weak keys and values interchangeably but didn't seem to work as intended all the time.
Cheers to implementing FlatCache, I'll be lurking for its release 😉
The text was updated successfully, but these errors were encountered: