Forum Discussion
Possible GENERATE_SERIES memory leak?
Hello iotsakp - thank you for reporting this issue and sharing the call stack. I can confirm that this issue is addressed. The fix has been included in SQL Server 2025 and had been included even earlier in Azure SQL Database. If I have any further information to share regarding the fix for SQL Server 2022, I will update this thread.
Hey Arvind, thank you for reply. I have faced the very same issue on SQL 2022 (16.0.4151.1) And it leaks ~ 400GB of RAM a week and it force us to restart the server. Do you have any details, when can we expect the fix?
The callstack is below
00 SqlDK!GenericEvent::PublishAndCallAction
01 SqlDK!XeSosPkg::page_allocated::Publish
02 SqlDK!MemoryClerkInternal::AllocatePagesWithFailureMode
03 SqlDK!MemoryClerkInternal::AllocatePages
04 SqlDK!CMemThread<CMemObj>::PbGetNewPages
05 SqlDK!TVarPageMgr<0>::PbAllocate
06 SqlDK!CMemObj::Alloc
07 SqlDK!CMemThread<CMemObj>::Alloc
08 SqlDK!operator new
09 sqllang!CTVFInfoGenSeries::PtiUserArgumentType
0a sqllang!CSTVFGenSeries::Init
0b sqlmin!CQScanTVFStreamNew::Open
0c sqlmin!CQScanNew::OpenHelper
0d sqlmin!CQScanStreamAggregateNew::Open
0e sqlmin!CQScanNLJoinNew::GetRow
0f sqlmin!CQScanLightProfileNew::GetRow
10 sqlmin!CQScanFilterNew::GetRowHelper
11 sqlmin!CBpQScanAdapter::BpGetNextBatchInternal
12 sqlmin!CBpQScan::GetNextBatch
13 sqlmin!CBpQScanSort::Accumulate
14 sqlmin!CBpQScanSort::BpOpen
15 sqlmin!CQScanBatchHelper::Open
16 sqlmin!CQScanNew::OpenHelper
17 sqlmin!CQScanStreamAggregateNew::Open
18 sqlmin!CQScanNew::OpenHelper
19 sqlmin!CQScanNew::OpenHelper
1a sqlmin!CQScanUpdateNew::Open
1b sqlmin!CQueryScan::StartupQuery
1c sqllang!CXStmtQuery::SetupQueryScanAndExpression
Also, i would recommend to use XE session with pairing to catch if you have same problem:
CREATE EVENT SESSION [Pairing_Mem_Leak_SOS] ON SERVER
ADD EVENT sqlos.page_allocated(
ACTION(package0.callstack)
WHERE ([memory_clerk_name]='MEMORYCLERK_SOSNODE')),
ADD EVENT sqlos.page_freed(
ACTION(package0.callstack)
WHERE ([memory_clerk_name]='MEMORYCLERK_SOSNODE'))
ADD TARGET package0.event_counter,
ADD TARGET package0.pair_matching(SET begin_event=N'sqlos.page_allocated',begin_matching_columns=N'memory_clerk_address,page_location',end_event=N'sqlos.page_freed',end_matching_columns=N'memory_clerk_address,page_location')
WITH (MAX_MEMORY=32768 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=5 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=PER_CPU,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO
- Arvind_ShyamsundarJul 22, 2025
Microsoft
Also The_Mike and iotsakp - I can confirm the fix for this issue has been delivered in SQL Server 2022 CU20, build 16.0.4205.1 (https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate20).
- Arvind_ShyamsundarJul 22, 2025
Microsoft
Thanks, The_Mike for letting me know about the event pair matching, that's a great suggestion!
Let me check on the status of the fix for SQL 2022; in the meantime can you confirm your build? 16.0.4151.1 does not appear to be any of the known builds (https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/build-versions)...