Skip to content

Conversation

@AdamEssenmacher
Copy link
Contributor

@AdamEssenmacher AdamEssenmacher commented Jan 16, 2024

Fixed #56 in MAUI. I don't know if the leak exists in Xamarin.Forms or not.

On iOS in MAUI, it's necessary to call DisconnectHandler() to prevent the CollectionView from leaking. This is a big issue since the leak will cascade through the .Parent property to the containing page and prevent it from being garbage collected.

This PR introduces a new BindableProperty on the CollectionView AutoDisconnectHandler, which is true by default and will call DisconnectHandler() during the Unload event.

I added the bindable property because, while automatically disconnecting the handler on unload is what most developers will want 99% of the time, you may not want this if the CollectionView is intentionally being temporarily removed from the main object tree. In these cases, the bindable property allows developers to opt out of this automatic behavior and assume responsibility for calling DisconnectHandler() themselves.

@roubachof roubachof merged commit 64359a8 into roubachof:main Jan 17, 2024
@roubachof
Copy link
Owner

Once again a very good catch, thanks Adam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory Leak in CollectionView

2 participants