- Notifications
You must be signed in to change notification settings - Fork2
Closed
Description
The following code in the privateSortResult function ofCountOccurences causes a memory leak:
procedureSortResult(var A:arrayof Generics.Collections.TPair<Integer,Cardinal>);begin Generics.Collections.TArray.Sort< Generics.Collections.TPair<Integer,Cardinal> >( A, Generics.Defaults.TDelegatedComparer< Generics.Collections.TPair<Integer,Cardinal> >.Create( function (const Left, Right: Generics.Collections.TPair<Integer,Cardinal>): Integerbegin Result := Left.Key - Right.Key;end ) );end;
The fix is to create the comparer outside the method call:
procedureSortResult(var A:arrayof Generics.Collections.TPair<Integer,Cardinal>);var Comparer: Generics.Defaults.IComparer< Generics.Collections.TPair<Integer,Cardinal> >;begin Comparer := Generics.Defaults.TDelegatedComparer< Generics.Collections.TPair<Integer,Cardinal> >.Create( function (const Left, Right: Generics.Collections.TPair<Integer,Cardinal>): Integerbegin Result := Left.Key - Right.Key;end ); Generics.Collections.TArray.Sort< Generics.Collections.TPair<Integer,Cardinal> >(A, Comparer);end;
Metadata
Metadata
Assignees
Labels
Projects
Status
Completed