roubachof / Sharpnado.CollectionView

A performant list view supporting: grid, horizontal and vertical layout, drag and drop, and reveal animations.
The Unlicense
244 stars 30 forks source link

Fixed memory leak in iOS/MAUI #112

Closed AdamEssenmacher closed 8 months ago

AdamEssenmacher commented 8 months ago

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 commented 8 months ago

Once again a very good catch, thanks Adam!