We have a problem with the latest realease of Rebex Https library (R6.1), because it seems to leak memory. To reproduce the issue I used the following program.
namespace cehttpstest
{
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Rebex;
using Rebex.Net;
class Program
{
static void Main(string[] args)
{
HttpRequestCreator creator = new HttpRequestCreator();
creator.Settings.SslAllowedSuites = TlsCipherSuite.RSA_WITH_AES_128_CBC_SHA256 |
TlsCipherSuite.RSA_WITH_AES_128_CBC_SHA;
creator.Settings.SslAcceptAllCertificates = true;
creator.Register();
while (true)
{
MemoryStatus status;
SendRequest(null);
GlobalMemoryStatusCE(out status);
Console.WriteLine("{0}", status);
Thread.Sleep(10000);
}
}
private static void SendRequest(object state)
{
Console.Write("Sending request... ");
HttpRequest request = (HttpRequest)WebRequest.Create("https://httpbin.org/post");
try
{
byte[] data = Encoding.UTF8.GetBytes(string.Format(@"
{{
""ticks"":{0},
""foo"":""bar""
}}", Environment.TickCount));
request.Method = "POST";
request.Accept = "*/*";
request.ContentType = "application/json";
request.ContentLength = data.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
using (var response = (HttpResponse)request.GetResponse())
{
Console.WriteLine("{0} (Length {1})", response.StatusCode, GetResponseString(response).Length);
}
}
catch (SystemException ex)
{
request.Abort();
Console.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
}
}
private static string GetResponseString(HttpResponse response)
{
StringBuilder sb = new StringBuilder(4096);
byte[] buf = new byte[8192];
using (var stream = response.GetResponseStream())
{
int count;
do
{
count = stream.Read(buf, 0, buf.Length);
if (count != 0)
{
// look for a UTF8 header
string result;
if ((buf[0] == 0xEF) && (buf[1] == 0xBB) && (buf[2] == 0xBF))
{
result = Encoding.UTF8.GetString(buf, 3, count - 3);
}
else
{
result = Encoding.UTF8.GetString(buf, 0, count);
}
sb.Append(result);
}
} while (count > 0);
response.Close();
}
return sb.ToString();
}
[Serializable]
private struct MemoryStatus
{
internal uint dwLength;
public int MemoryLoad;
public int TotalPhysical;
public int AvailablePhysical;
public int TotalPageFile;
public int AvailablePageFile;
public int TotalVirtual;
public int AvailableVirtual;
public override string ToString()
{
return string.Format
("Load: {0,3} TotalPhys: {1,10} AvailPhys: {2,10} TotalVirt: {3,10} AvailVirt: {4,10}",
MemoryLoad, TotalPhysical, AvailablePhysical, TotalVirtual, AvailableVirtual);
}
}
[DllImport("coredll", EntryPoint = "GlobalMemoryStatus", SetLastError = false)]
private static extern void GlobalMemoryStatusCE(out MemoryStatus msce);
}
}
On my device (ARM9 with 64MB, running Windows CE 6.0 with .NET CF3.5) it eats up all the available free memory in around 40 minutes.
Downgrading the library to R5 seems to solve the issue.
Could you please help us with this problem?
Thanks in advance!