Session memory leaks in 9.4

Ok so I’m actually back where I started. Since I’m adding these sessions to the manager, they should be freed but obviously aren’t.

I’m going to put some debug code it and track exactly when they’re created and destroyed.

It seems it’s only happening sometimes.

I can see the sessions being created and destroyed but sometimes one of them isn’t destroyed and I get the memory leak message.

I’ll try to look into it some more next week and work out why it’s not being freed.

Apologies, I’ve been on leave for the last two weeks.

Been looking at this again and I believe I’ve found the problem.

In TROInMemorySessionManager.DoClearSessions, you have this code:

for s in fSessionList.Values do
DeleteSession(s.SessionID, False);

This isn’t working correctly in all cases. I’ve found that sometimes it calls DeleteSession for every element and sometimes I misses some of them, causing the leak.

On further investigation, it appears this is a known issue:delphi xe2 - How to iterate a TDictionary and delete item? - Stack Overflow

To test, I tried changing the code to dump the sessions into an array first:

a := fSessionList.Values.ToArray;
for i := Low(a) to High(a) do
DeleteSession(a[i].SessionID, False);

And this works correctly in all cases.

Thanks, logged as bugs://80521

bugs://80521 got closed with status fixed.

Is your solution the same as mine and/or is there anything else which needs changing?

almost the same.
you need to apply it to OnlyExpired section too

Ok thanks