-
Notifications
You must be signed in to change notification settings - Fork 70
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
feature: rehabilitates the HasDisposeBag protocol #49
Conversation
Which mean 'struct' type will implement it by considering if swift reuse instance of that struct, then along with |
@grinder81 i'm not sure I see your point. Can you provide an example so I can answer your question more precisely ? Thx. |
In Swift, struct is a value type which means memory handled in stack for struct, not in heap (like class as reference type) which indicate life cycle and reusability of a struct instance handled by swift compiler. When compiler is going reuse of an instance then associated bag also moving with it. So my question is what will happen in the following case: Struct:
and that struct adopted My point could be wrong, I just want to verify. Let's discuss. Thanks |
Mmm, that makes sense. I think this passes in the test case because Swift structs are copy-on-write, so they are the same instance until one has been written to. Anyone available to test? |
I get your point. When Struct B will be instantiated, Swift will reuse the stack allocated for A and use its associated DisposeBag ? We do net get a brand new DisposeBag. |
As this is a tricky issue, I will ask the swift developers and send a message to their mailing-list. I'll get back to you as soon as the Swift compiler guys give me an answer about how the compiler handles the stack reusability. |
Hi guys, Greg Parker (from the swift-dev mailling list) has answered my email. He thinks this is not safe to use objc_setAssociatedObject() as well as objc_sync_enter/exit. I think I will modify the protocol to add a :class conformance (protocol HasDisposeBag: class). |
Yeah, that makes sense. Thanks for following up 👍 |
The HasDisposeBag protocol is back, but doest not share anymore code with AnyObject, so there is no collision between self and base references The HasDisposeBag protocol can only be implemented by a class, as it uses objc_setAssociatedObject. It is safer from a memory management point of view.
a599a71
to
ab5c60f
Compare
Hi guys @ashfurrow @grinder81. I've just pushed a safer version of the HasDisposeBag protocol. |
@ashfurrow the CI fails and I can't figure out why. It seems to be a RxSwift compilation problem. Do you have a clue ? |
Looks like CI is using Xcode 8.3. I’m planning to switch CI providers on Monday, so we can test that it works on your PR :) |
@ashfurrow Hi Ash, Have you been able to switch to Circle CI ? |
Heya! Almost: Circle CI have graciously given us free access to the macOS infrastructure. I'm discussing it with them now and will report back with a PR when we're ready 👍 |
@ashfurrow hope the setup of |
The HasDisposeBag PR RxSwiftCommunity#49 should add it back.
Hi @ashfurrow how is it going with CI ... is there a chance my PR will be merged soon ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 👍 We're having some issues integrating with Circle (they're support team is working on it, they're great) but I'm fine merging this as-is.
@ashfurrow great. Please go ahead. Thanks. |
Cool, thanks a lot! Do you think we should put out a point-release with this? |
HasDisposeBag.swift was removed as a reference from xcodeproj in #55 (it was at an incorrect file path anyway). We have to add the correct reference before the next release. |
Cool, this has been released as version 4.2.0. Thanks again! |
the HasDisposeBag protocol is back, but doest not share anymore code
with AnyObject extension, so there is no collision between self and base references