-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context: https://github.com/jonathanpeppers/memory-analyzers Context: https://www.nuget.org/packages/MemoryAnalyzers/0.1.0-beta.1 This adds a new Roslyn analyzer that warns about the following cases. ## MA0001 Don't define `public` events in `NSObject` subclasses: ```csharp public class MyView : UIView { // NOPE! public event EventHandler MyEvent; } ``` ## MA0002 Don't declare members in `NSObject` subclasses unless they are: * `WeakReference` or `WeakReference<T>` * Value types ```csharp class MyView : UIView { // NOPE! public UIView? Parent { get; set; } public void Add(MyView subview) { subview.Parent = this; AddSubview(subview); } } ``` ## MA0003 Don't subscribe to events inside `NSObject` subclasses unless: * It's your event via `this.MyEvent` or from a base type. * The method is `static`. ```csharp class MyView : UIView { public MyView() { var picker = new UIDatePicker(); AddSubview(picker); picker.ValueChanged += OnValueChanged; } void OnValueChanged(object sender, EventArgs e) { } // Use this instead and it doesn't leak! //static void OnValueChanged(object sender, EventArgs e) { } } ``` This is also on NuGet, but I just commited the package until we can get it added to the `dotnet-public` feed. I've marked a couple places OK, but `Core.csproj` will currently be at: [src\Core\src\Core.csproj::TargetFramework=net7.0-ios] 32 Error(s)
- Loading branch information
1 parent
b2b791c
commit bfa594e
Showing
5 changed files
with
9 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters