When you run the package, you can sometimes see the following error message if you use Script component in the package:
System.Runtime.InteropServices.COMException (0x8002000d): Memory is locked. (Exception from hresult:0x8002000d (disp_e_arrayislocked))
At Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException (Exception e)
At Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput (Int32 inputID, PipelineBuffer buffer)
At Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput (IDTSManagedComponentWrapper100 Wrapper , Int32 inputID, IDTSBuffer100 pdtsbuffer, IntPtr bufferwirepacket)
In the case of using Script component in the package, it is generally the use of regular expressions to process string data, in my package, there is a Regex object, the test shows that the regex has memory leak bug, the analysis process, Please see the documentation referenced in the reference document
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
byte[] source = Row.Body.GetBlobData(0, (int)Row.Body.Length);
string sinput = Encoding.Unicode.GetString(source, 0, source.Length);
string spattern = @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?";
List<string> returns = new List<string>();
try
{
Regex regex = new Regex(spattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
var values = regex.Matches(sinput);
if (values != null && values.Count > 0)
{
//----------
}
}
catch
{
}
}
Scenario Follow:
Because Input0_processinputrow has the same number of calls and rows of data, you can put the following two pieces of code into the PreExecute function, avoid creating regex objects frequently, and create a Regex regex field in class scope.
String spattern = @ "(HTTP|FTP|HTTPS): \/\/[\w\-_]+ (\.[ \w\-_]+) + ([\w\-\.,@?^=%&:/ ~\+#]*[\w\-\@?^=%&/~\+#])? ";
Regex = New Regex (Spattern, regexoptions.ignorecase | Regexoptions.multiline);
Reference Documentation:
http://blogs.msdn.com/b/bclteam/archive/2006/10/19/ Regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx
Http://stackoverflow.com/questions/11174366/c-sharp-memory-leak
Http://stackoverflow.com/questions/2734766/net-regex-memory-leak-investigation
SSIS Memory is locked and RegEx