Spring4D TWhereEnumerator does not release its interface reference to fSource.

Spring4D TWhereEnumerator does not release its interface reference to fSource.

Current code:

constructor TWhereIterator.Create(const source: IEnumerable;
const predicate: TPredicate);
begin
{$IFDEF SPRING_ENABLE_GUARD}
Guard.CheckNotNull(Assigned(source), 'source');
Guard.CheckNotNull(Assigned(predicate), 'predicate');
{$ENDIF}

inherited Create(source.Comparer);
fSource := source;
fPredicate := predicate;
end;

function TWhereIterator.Clone: TIterator;
begin
Result := TWhereIterator.Create(fSource, fPredicate);
end;

function TWhereIterator.MoveNext: Boolean;
var
current: T;
begin
Result := False;

if fState = STATE_ENUMERATOR then
begin
fEnumerator := fSource.GetEnumerator;
fState := STATE_RUNNING;
end;

if fState = STATE_RUNNING then
begin
while fEnumerator.MoveNext do
begin
current := fEnumerator.Current;
if fPredicate(current) then
begin
fCurrent := current;
Exit(True);
end;
end;
fState := STATE_FINISHED;
fEnumerator := nil;
end;
end;


Fix:

destructor TSourceIterator.Destroy;
begin
fSource:= nil;
inherited Destroy;
end;

Or perhaps I'm missing something.
I'd post an issue to Spring4D, but I don't seem to be able to post issues.

Comments

  1. @Jacek Laskowski OMG, usually people deploy master branch of 3rd party library. So we have done :) But ITree is in the DynArrayTrees branch. Little bit not obvious, isn't it? I am almoust sure Johan has plans to merge the branchs.

    -1for the irony, +1 for the help :) Thanks.

    ReplyDelete
  2. Alex Matveev The DynArray branch is experimental. As soon as I has a set of test cases running I will merge it into the master branch.

    ReplyDelete
  3. Johan Bontes Thanks a lot. So I thought. We are waiting for the realease to use ITree.

    ReplyDelete

Post a Comment