Skip to content

Instantly share code, notes, and snippets.

@dagvl
Created November 4, 2011 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagvl/1339646 to your computer and use it in GitHub Desktop.
Save dagvl/1339646 to your computer and use it in GitHub Desktop.
Minimal example that shows memory issues
using System;
using System.Runtime.Serialization;
using System.Threading;
using Funq;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.WebHost.Endpoints;
namespace MemLeakTest
{
[DataContract]
[RestService("/f", Verbs = "POST")]
class FileDto { }
class AppHost : AppHostHttpListenerBase
{
public AppHost()
: base("Test memleak", typeof(FileService).Assembly) { }
public override void Configure(Container container)
{
container.Register(new FileService());
}
}
class FileService : RestServiceBase<FileDto>
{
public override object OnPost(FileDto request)
{
return new FileDto();
}
}
class Program
{
static void Main(string[] args)
{
var from = DateTime.Now;
var appHost = new AppHost();
appHost.Init();
appHost.Start("http://*:7546/");
while (true)
{
var to = DateTime.Now;
var time = to - from;
//Console.Write("\rMem used: {0} mb ", GC.GetTotalMemory(false) / (1024 * 1024));
Console.Write("{0} {1}\n", time.TotalSeconds, GC.GetTotalMemory(false));
Thread.Sleep(500);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment