Skip to content

Commit 797fc69

Browse files
authored
Merge pull request #297 from servicetitan/upstream/FixColumnInfoCollectionLeak
Fix ColumnInfoCollection & NodeCollection<AssociationInfo> leaks; refactor IndexInfo class
2 parents 2eb8ee4 + 721500e commit 797fc69

File tree

4 files changed

+96
-107
lines changed

4 files changed

+96
-107
lines changed

Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.ConcreteTable.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private void BuildConcreteTableIndexes(TypeInfo type)
3434
continue;
3535
}
3636

37-
var declaredIndex = BuildIndex(type, indexDescriptor, type.IsAbstract);
37+
var declaredIndex = BuildIndex(type, indexDescriptor, type.IsAbstract);
3838
type.Indexes.Add(declaredIndex);
3939
if (!declaredIndex.IsAbstract) {
4040
context.Model.RealIndexes.Add(declaredIndex);
@@ -46,7 +46,7 @@ private void BuildConcreteTableIndexes(TypeInfo type)
4646
if (parent != null) {
4747
var parentPrimaryIndex = parent.Indexes.FindFirst(IndexAttributes.Primary | IndexAttributes.Real);
4848
var inheritedIndex = BuildInheritedIndex(type, parentPrimaryIndex, type.IsAbstract);
49-
49+
5050
// Registering built primary index
5151
type.Indexes.Add(inheritedIndex);
5252
if (!inheritedIndex.IsAbstract) {
@@ -63,6 +63,7 @@ private void BuildConcreteTableIndexes(TypeInfo type)
6363

6464
var index = BuildInheritedIndex(type, parentIndex, type.IsAbstract);
6565
if ((parent != null && parent.Indexes.Contains(index.Name)) || type.Indexes.Contains(index.Name)) {
66+
index.Dispose();
6667
continue;
6768
}
6869

Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private void CreateInterfaceIndexes(TypeInfo @interface, ICollection<TypeInfo> p
9292
foreach (var parentIndex in parent.Indexes.Find(IndexAttributes.Primary, MatchType.None).ToChainedBuffer()) {
9393
var index = BuildInheritedIndex(@interface, parentIndex, false);
9494
if (@interface.Indexes.Contains(index.Name)) {
95+
index.Dispose();
9596
continue;
9697
}
9798

@@ -169,8 +170,8 @@ private void BuildInterfaceIndexes()
169170
indexesToJoin.Add(filterIndex);
170171
indexesToJoin.AddRange(typeIndexes);
171172

172-
var indexToApplyView = indexesToJoin.Count > 1
173-
? BuildJoinIndex(implementor, indexesToJoin)
173+
var indexToApplyView = indexesToJoin.Count > 1
174+
? BuildJoinIndex(implementor, indexesToJoin)
174175
: indexesToJoin[0];
175176
var indexView = BuildViewIndex(@interface, indexToApplyView);
176177
underlyingIndex.UnderlyingIndexes.Add(indexView);
@@ -204,8 +205,10 @@ private void BuildInterfaceIndexes()
204205
}
205206
underlyingIndexes.Add(underlyingIndex);
206207
}
207-
if (underlyingIndexes.Count == 1)
208+
if (underlyingIndexes.Count == 1) {
209+
index.Dispose();
208210
index = underlyingIndexes.First();
211+
}
209212
else
210213
index.UnderlyingIndexes.AddRange(underlyingIndexes);
211214

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ public override void Lock(bool recursive)
675675
column.Lock(true);
676676
if (associations.Count > 1) {
677677
var sorted = associations.Reorder();
678+
associations.Clear();
678679
associations = new NodeCollection<AssociationInfo>(associations.Owner, associations.Name);
679680
associations.AddRange(sorted);
680681
}

0 commit comments

Comments
 (0)