fccd43f0c2
Problems: * `Dispose` set the generated backing fields to `null` which means the linker will mark every backing fields, even if not used elsewhere (generally properties) inside the class * Backing fields increase the memory footprint of the managed peer instance (for the type and all it's subclasses) * Backing fields also increase the app size. Not a huge problem as they are all declared _weakly_ as `NSObject` but still... Solution: * When the linker process a `Dispose` method of an `NSObject` subclass with the _optimizable_ attribute then we remove the method body. This way the linker cannot mark the fields. * Before saving back the assemblies we replace the cached method body and NOP every field that were not marked by something else than the `Dispose` method. ```diff --- a.cs 2021-06-22 16:56:57.000000000 -0400 +++ b.cs 2021-06-22 16:57:00.000000000 -0400 @@ -3107,8 +3107,6 @@ private static readonly IntPtr class_ptr = Class.GetHandle("UIApplication"); - private object __mt_WeakDelegate_var; - public override IntPtr ClassHandle => class_ptr; [DllImport("__Internal")] @@ -3141,9 +3139,8 @@ protected override void Dispose(bool P_0) { base.Dispose(P_0); - if (base.Handle == IntPtr.Zero) + if (!(base.Handle == IntPtr.Zero)) { - __mt_WeakDelegate_var = null; } } } @@ -3209,10 +3206,6 @@ { private static readonly IntPtr class_ptr = Class.GetHandle("UIScreen"); - private object __mt_FocusedItem_var; - - private object __mt_FocusedView_var; - public override IntPtr ClassHandle => class_ptr; public virtual CGRect Bounds @@ -3242,10 +3235,8 @@ protected override void Dispose(bool P_0) { base.Dispose(P_0); - if (base.Handle == IntPtr.Zero) + if (!(base.Handle == IntPtr.Zero)) { - __mt_FocusedItem_var = null; - __mt_FocusedView_var = null; } } } @@ -3254,10 +3245,6 @@ { private static readonly IntPtr class_ptr = Class.GetHandle("UIView"); - private object __mt_ParentFocusEnvironment_var; - - private object __mt_PreferredFocusedView_var; - public override IntPtr ClassHandle => class_ptr; public virtual CGRect Bounds @@ -3303,10 +3290,8 @@ protected override void Dispose(bool P_0) { base.Dispose(P_0); - if (base.Handle == IntPtr.Zero) + if (!(base.Handle == IntPtr.Zero)) { - __mt_ParentFocusEnvironment_var = null; - __mt_PreferredFocusedView_var = null; } } } @@ -3315,12 +3300,6 @@ { private static readonly IntPtr class_ptr = Class.GetHandle("UIViewController"); - private object __mt_ParentFocusEnvironment_var; - - private object __mt_PreferredFocusedView_var; - - private object __mt_WeakTransitioningDelegate_var; - public override IntPtr ClassHandle => class_ptr; public virtual UIView View @@ -3363,11 +3342,8 @@ protected override void Dispose(bool P_0) { base.Dispose(P_0); - if (base.Handle == IntPtr.Zero) + if (!(base.Handle == IntPtr.Zero)) { - __mt_ParentFocusEnvironment_var = null; - __mt_PreferredFocusedView_var = null; - __mt_WeakTransitioningDelegate_var = null; } } } @@ -3376,8 +3352,6 @@ { private static readonly IntPtr class_ptr = Class.GetHandle("UIWindow"); - private object __mt_WindowScene_var; - public override IntPtr ClassHandle => class_ptr; public virtual UIViewController RootViewController @@ -3411,9 +3385,8 @@ protected override void Dispose(bool P_0) { base.Dispose(P_0); - if (base.Handle == IntPtr.Zero) + if (!(base.Handle == IntPtr.Zero)) { - __mt_WindowScene_var = null; } } } ``` * Do not consider bindings with `[Dispose (...)]` as optimizable Injected code makes it impossible for `bgen` to decide if it's optimizable (or not) Filed https://github.com/xamarin/xamarin-macios/issues/12150 with more details (and for other similar attributes) |
||
---|---|---|
.github/workflows | ||
Localize | ||
builds | ||
docs | ||
dotnet | ||
eng | ||
external | ||
fsharp | ||
jenkins | ||
mk | ||
mono | ||
msbuild | ||
opentk | ||
runtime | ||
src | ||
tests | ||
tools | ||
.editorconfig | ||
.gitignore | ||
.gitmodules | ||
CODEOWNERS | ||
ISSUE_TEMPLATE.md | ||
LICENSE | ||
Make.config | ||
Make.versions | ||
Makefile | ||
NOTICE.txt | ||
NuGet.config | ||
README.md | ||
SECURITY.MD | ||
Versions-ios.plist.in | ||
Versions-mac.plist.in | ||
Xamarin.Mac.sln | ||
Xamarin.iOS.sln | ||
banner.png | ||
configure | ||
global.json | ||
mac-entitlements.plist | ||
product.snk | ||
system-dependencies.sh | ||
versions-check.csharp |
README.md
Xamarin.iOS & Xamarin.Mac
Welcome!
This module is the main repository for both Xamarin.iOS and Xamarin.Mac.
These SDKs allow us to create native iOS, tvOS, watchOS and macOS applications using the same UI controls we would in Objective-C and Xcode, except with the flexibility and elegance of a modern language (C#), the power of the .NET Base Class Library (BCL), and two first-class IDEs—Visual Studio for Mac and Visual Studio—at our fingertips.
This repository is where we do development for the Xamarin.iOS and Xamarin.Mac SDKs. There are a few ways that you can contribute, for example:
- Submit bugs and feature requests
- Review source code changes
- Submit pull requests to resolve issues and fix bugs
Contributing
If you are interested in fixing issues and contributing directly to the code base, please see the document How to Contribute, which covers the following:
- How to build and run from source
- The development workflow, including debugging and running tests
- Coding Guidelines
- Submitting pull requests
Downloads
The preferred method for installing Xamarin.iOS and Mac is to use the Visual Studio installers (Windows, Mac).
The team also strongly recommends using the latest Xamarin SDK and Xcode whenever possible.
However, we provide links to older Xamarin.iOS and Mac packages for macOS downgrades and build machine configuration.
Version | Xamarin.iOS | Xamarin.Mac |
---|---|---|
d16.9 (Xcode 12.5) | 14.16.0.5 | 7.10.0.5 |
d16.9 | 14.14.2.5 | 7.8.2.5 |
d16.8 (Xcode 12.4) | 14.10.0.4 | 7.4.0.10 |
d16.8 (Xcode 12.3) | 14.8.0.3 | 7.2.0.3 |
d16.8 (Xcode 12.2) | 14.6.0.15 | 7.0.0.15 |
d16.8 | 14.4.1.3 | 6.22.1.26 |
d16.7 | 14.2.0.12 | 6.20.2.2 |
d16.6 | 13.18.2.1 | 6.18.2.1 |
d16.5 | 13.16.0.13 | 6.16.0.13 |
d16.4 | 13.10.0.21 | 6.10.0.21 |
d16.3 | 13.6.0.12 | 6.6.0.12 |
d16.2 | 12.14.0.114 | 5.14.0.114 |
d16.1 | 12.10.0.157 | 5.10.0.157 |
d16.0 | 12.8.0.2 | 5.8.0.0 |
Feedback
- Ask a question on Stack Overflow or the Xamarin Forums
- Request a new feature on GitHub
- Vote on existing feature requests
- Submit bugs to GitHub Issues
- Discuss development and design on Discord
License
Copyright (c) .NET Foundation Contributors. All rights reserved. Licensed under the MIT License.