Skip to content

Commit 569851f

Browse files
authored
Merge pull request #226 from servicetitan/ColumnInfoCollection_MemoryLeak
Fix Memory (event handlers) leak of ColumnInfoCollection objects
2 parents 13f878f + 44c066f commit 569851f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Orm/Xtensive.Orm/Orm/Model/FieldInfo.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2007-2021 Xtensive LLC.
1+
// Copyright (C) 2007-2022 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Dmitri Maximov
@@ -627,6 +627,7 @@ public ColumnInfoCollection Columns
627627

628628
var result = new ColumnInfoCollection(this, "Columns");
629629
GetColumns(result);
630+
columns = result;
630631
return result;
631632
}
632633
}
@@ -660,8 +661,8 @@ public override void UpdateState()
660661
Fields.UpdateState();
661662
if (column != null)
662663
column.UpdateState();
663-
columns = new ColumnInfoCollection(this, "Columns");
664-
GetColumns(columns);
664+
columns?.Clear(); // To prevent event handler leak
665+
columns = null;
665666

666667
HasImmediateValidators = validators.Count > 0 && validators.Any(v => v.IsImmediate);
667668

Orm/Xtensive.Orm/Orm/Model/TypeInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2007-2020 Xtensive LLC.
1+
// Copyright (C) 2007-2022 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Dmitri Maximov
@@ -38,7 +38,7 @@ public sealed class TypeInfo : SchemaMappedNode
3838
/// </summary>
3939
public const int MinTypeId = 100;
4040

41-
private ColumnInfoCollection columns;
41+
private readonly ColumnInfoCollection columns;
4242
private readonly FieldMap fieldMap;
4343
private readonly FieldInfoCollection fields;
4444
private readonly TypeIndexInfoCollection indexes;
@@ -747,8 +747,8 @@ private bool GetIsLeaf()
747747

748748
private void CreateTupleDescriptor()
749749
{
750-
var orderedColumns = columns.OrderBy(c => c.Field.MappingInfo.Offset);
751-
columns = new ColumnInfoCollection(this, "Columns");
750+
var orderedColumns = columns.OrderBy(c => c.Field.MappingInfo.Offset).ToList(columns.Count);
751+
columns.Clear(); // To prevent event handler leak
752752
columns.AddRange(orderedColumns);
753753
TupleDescriptor = TupleDescriptor.Create(
754754
Columns.Select(c => c.ValueType).ToArray(Columns.Count));

0 commit comments

Comments
 (0)