Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Memory leak inCountOccurences snippet in Mathematics category #54

Closed
Assignees
delphidabbler
Labels
bugSomething isn't workingcompletedIssue completed and committed to develop. To be closed on next release
@delphidabbler

Description

@delphidabbler

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

bugSomething isn't workingcompletedIssue completed and committed to develop. To be closed on next release

Projects

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp