Skip to content

Avalonia DataGrid Memory Leak: 300MB → 2GB+ with specific data patterns in v12.0.0 #228

@4Darmygeometry

Description

@4Darmygeometry

Describe the bug

When upgrading from Avalonia 11.3.13 to 12.0.0, the DataGrid control exhibits a severe memory leak issue with specific real-world data patterns. Displaying 1000+ rows of warehouse control system (WCS) task data causes memory usage to spike from approximately 300MB to over 2GB. Additionally, the initial query performance degrades significantly.

See the screenshot below:

Image Image Image

Important: This issue cannot be reproduced with simple mock data (English strings only). It requires specific data characteristics:

  • Mixed Chinese/English text content
  • Multiple data types: int, string, DateTime, nullable DateTime?
  • 18+ columns with StringFormat bindings for dates
  • Real database query results (not synthetic data)

This makes Avalonia 12.x unusable for enterprise applications displaying complex real-world datasets.

To Reproduce

Note: Minimal reproduction with mock data does NOT trigger this issue. The problem only manifests with real database data having the characteristics described above.

Steps:

  1. Use the attached complete project WCS.Avalonia.zip (114.5KB)
  2. Restore the attached database (contains WCS task data)
  3. Run the application with Avalonia 12.0.0
  4. Navigate to the task query page
  5. Load 1000+ rows of task data
  6. Observe memory usage in Task Manager or VS Diagnostic Tools

Attached Files:

Data Characteristics That Trigger the Issue:

// Model with mixed types and Chinese content
public class TaskItem
{
    public int Id { get; set; }
    public string TaskTypeName { get; set; } // "入库", "出库", "任务完成成功"
    public DateTime CreateTime { get; set; }
    public DateTime? StartTime { get; set; } // Nullable dates
    public DateTime? EndTime { get; set; }
    // ... 14 more columns
}

XAML with date formatting:

<DataGridTextColumn Header="创建时间" 
                    Binding="{Binding CreateTime, StringFormat='yyyy/M/d HH:mm:ss'}" />

What We Tried (Does NOT Reproduce)

We attempted to create a minimal reproduction with:

  • Simple English string data only → Memory stays normal (~300MB)
  • Mock data with same structure → Cannot reproduce the leak
  • Same row count (1000+) → No issue with synthetic data

Only the complete project with real database triggers the 2GB+ memory spike.

Expected behavior

Memory usage should remain stable around 300-400MB for 1000 rows (as in v11.3.13)
Initial query and display should be fast and responsive
No significant memory growth when scrolling or interacting with the DataGrid

Avalonia version

12.0.0

OS

Windows

Additional context

Data Pattern Analysis

The issue appears to be triggered by specific combinations:

  1. Chinese characters in string fields (task status descriptions)
  2. DateTime formatting via StringFormat in XAML bindings
  3. Nullable DateTime fields (DateTime?)
  4. 18 columns with mixed data types
  5. Real database query results (not in-memory generated data)

Verification

  • Downgrading to Avalonia 11.3.13 completely resolves the issue
  • Other packages (MySqlConnector, Microsoft.Data.SqlClient, etc.) ruled out
  • Same data access code and view models work fine in 11.3.13
  • Issue is reproducible 100% of the time with attached files

Impact

This is a critical regression that prevents upgrading to Avalonia 12.x for enterprise applications displaying real-world datasets with:

  • International character sets (Chinese, Japanese, etc.)
  • Complex data types and formatting
  • Database-driven DataGrid displays

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions