https://github.com/jonathanpeppers/memory-analyzers
C# code analyzers for finding memory leaks
https://github.com/jonathanpeppers/memory-analyzers
catalyst dotnet hacktoberfest ios maui memory-leak
Last synced: 3 months ago
JSON representation
C# code analyzers for finding memory leaks
- Host: GitHub
- URL: https://github.com/jonathanpeppers/memory-analyzers
- Owner: jonathanpeppers
- License: mit
- Created: 2023-07-18T14:56:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-30T19:14:48.000Z (almost 2 years ago)
- Last Synced: 2025-04-04T23:51:07.388Z (7 months ago)
- Topics: catalyst, dotnet, hacktoberfest, ios, maui, memory-leak
- Language: C#
- Homepage:
- Size: 518 KB
- Stars: 43
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# memory-analyzers
[](https://www.nuget.org/packages/MemoryAnalyzers/)
A set of Roslyn C# code analyzers for finding memory leaks in iOS and
MacCatalyst applications -- with potentially other ideas in the future.For more information on the "circular reference" problem on Apple platforms,
see:* https://github.com/dotnet/maui/wiki/Memory-Leaks#circular-references-on-ios-and-catalyst
Note that this "circular reference" situation would occur in Swift or
Objective-C, so it is not a .NET-specific problem. It does not occur on Android
or Windows platforms.## 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`
* 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) { }
}
```