Skip to content
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

Fixed the unbound memory growth of unidirectional bindings. #176

Merged
merged 1 commit into from
Dec 22, 2016

Conversation

andersio
Copy link
Member

@andersio andersio commented Dec 22, 2016

	if let disposable = disposable {
		target.lifetime.ended.observeCompleted { disposable.dispose() }
	}

would leave the disposable of a disposed binding in the lifetime signal forever (until the lifetime ends).

I also notice one thing — observe would show up in the code completion of Property and SignalProducer, but neither use this term. Perhaps it would be better to rename it to bind(_:during:).

@andersio andersio added the bug label Dec 22, 2016
@andersio andersio requested a review from mdiep December 22, 2016 17:45
@andersio
Copy link
Member Author

andersio commented Dec 22, 2016

This doesn't seem the only leak though...

@liscio
Copy link
Contributor

liscio commented Dec 22, 2016

Changes look good, but I agree that the naming is unfortunate. I initially wondered why observe had to be changed everywhere and then realized my misunderstanding.

With that said, what are your thoughts on addObserver(_:during:)?

@andersio
Copy link
Member Author

Based on the API guidelines, it should be add(_:during:) though.

@andersio
Copy link
Member Author

andersio commented Dec 22, 2016

It seems there are some edgy cases in the binding model that haven't been caught. Our primitives themselves aren't leaking.

@mdiep
Copy link
Contributor

mdiep commented Dec 22, 2016

Can we add a test for this?

@mdiep
Copy link
Contributor

mdiep commented Dec 22, 2016

I actually like the name as-is. The reality is that a Property or SignalProducer can be observed.

@andersio
Copy link
Member Author

I actually like the name as-is. The reality is that a Property or SignalProducer can be observed.

SignalProducer cannot be observed. It produces a Signal that can be observed, aka start. It fits Property, but then observe and start have a different semantic in Property where the binding is using start.

Can we add a test for this?

Probably not. There is no public or internal API to catch the number of observers.

@mdiep
Copy link
Contributor

mdiep commented Dec 22, 2016

SignalProducer cannot be observed. It produces a Signal that can be observed, aka start.

Even if it can't be observed directly, it can be observed. At any rate, this method is clearly side-effecting, so it deserves a direct verb name. Something like add won't do it justice.

Can we add a test for this?

Probably not. There is no public or internal API to catch the number of observers.

If it's disposable that's getting leaked, we should be able to do a standard weak test where we verify that it gets cleared at the appropriate time?

@andersio
Copy link
Member Author

andersio commented Dec 22, 2016

If it's disposable that's getting leaked, we should be able to do a standard weak test where we verify that it gets cleared at the appropriate time?

True without this fix, where the Lifetime observation shares the same disposable that is returned. But this fix internalised it with take(during:).

We may setup some burning tests that compares memory before and after the burning though.

@andersio
Copy link
Member Author

Even if it can't be observed directly, it can be observed. At any rate, this method is clearly side-effecting, so it deserves a direct verb name. Something like add won't do it justice.

I am not disagreeing with that. Just that observe has an established meaning that does not belong to at least the domain of SignalProducer — we have start as the MVP there. Now imagine an entry in code completion shows up with observe...

@andersio andersio merged commit b0a3b3d into master Dec 22, 2016
@andersio andersio deleted the binding-limit-memory-growth branch December 22, 2016 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants