Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Problem with XML parser memory leak

$
0
0

We're using xml parameters to send a collection of data to stored procedure.
Typical (little simplified) use case would look like:

DECLARE @Values varchar(max) = '<Root><S>1</S><S>2</S><S>3</S></Root>', @h int
DECLARE @Val TABLE(ID smallint)

EXEC    sp_xml_preparedocument @h OUTPUT, @Values
INSERT INTO @Val(ID)
SELECT DISTINCT ID FROM OpenXML(@h,'Root/S',8)  WITH (ID smallint 'text()')
EXEC sp_xml_removedocument @h

SELECT * FROM @Val

We know we have to properly "pair" sp_xml_preparedocument /sp_xml_removedocument to avoid memory leaks.
Normally, our server works for months without any problems.

(I have to use external image because your portal is giving me "Body text cannot contain images or links until we are able to verify your account." error message)    https://imgpile.com/i/I5kAUR

At some point in time we're able to observe a constant growth of xml parser memory usage.
Our system still works, but it appears as if no document is being properly "removed", so our memory
usage graph begins to steadily grow.

(I have to use external image because your portal is giving me "Body text cannot contain images or links until we are able to verify your account." error message)    https://imgpile.com/i/I5kLYg

In the graph above 1.5K represents 1500MB. The only way to stop this endless growth is to restart
SQL Server service. After that it starts working just fine.

Is there a way to reclaim back all memory (some kind of overall xml parser memory "reset") without
rebooting the whole service?
Since our stored procedures are running pretty quickly (few seconds max.) is there a way to reclaim
all memory allocated by sp_xml_preparedocument which execution moment is older then some predefined time
(that would simply deallocate all "old" memory used by "old" xml documents)?

Any help would be very useful.

We're using version: Microsoft SQL Server 2014 (SP3-CU4) (KB4500181) - 12.0.6329.1 (X64)   Jul 20 2019 21:42:29   Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )

We also had identical problem with SQL Server 2012.


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>