Skip to content

Many controls (mainly iOS) are not collected by GC  #18365

@heyThorsten

Description

@heyThorsten

Description

I'm working on an app for iOS. The app creates new instances of pages and view models every time a new page is pushed to the navigation stack. After a while the app gets very slow and crashes.
So I started to comment out parts of XAML and to trigger GC and found that the pages were no longer cleaned up if they had certain controls.

To find out which controls causes problems I created a simple test programme that does nothing more than adding one single control to a page and pushes that page onto the navigation stack. By clicking a button the garbage collector can be forced to work. The program outputs a debug message when the constructor and finaliser of the opened page is called.

On iOS there are many controls where there is no finaliser call of the page, resulting in memory leaks.

On iOS there is no finaliser log output (~xxx Page) for these controls:

On Windows there is no finaliser log output (~xxx Page) for these controls:

On Android there is no finaliser log output (~xxx Page) for these controls:

2023-10-26 10_35_42-Air-von-Jens fritz box - TeamViewer

Steps to Reproduce

  1. Clone repository.
  2. Run App.
  3. Press any button to open a new page.
  4. Notice "xxx Page" output (output from constructor).
  5. Navigate back.
  6. Press button "GC.Collect"
  7. Notice "~xxx Page" output (output from finaliser)

Link to public reproduction project repository

https://github.com/heyThorsten/GCTest

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows

Affected platform versions

iOS 16.4 (Simulator), Android 10.0 (Emulator), Windows 10.0.19041.0

Did you find any workaround?

No response

Relevant log output

JUST AN EXAMPLE (WebView Page finaliser call is missing):
Label Page
ScrollView Page
WebView Page
Ellipse Page
GC.Collect()
GC.Collect()
~Ellipse Page
~Label Page
~ScrollView Page

Metadata

Metadata

Labels

area-controls-generalGeneral issues that span multiple controls, or common base classes such as View or Elementp/1Work that is important, and has been scheduled for release in this or an upcoming sprintperf/generalThe issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)perf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)platform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions