Since your worker role instances are Windows Server 2012, you can just set up an appropriate perf counter during role startup ( OnStart()
) with whichever pertinent Memory
counters you're interested in, and set up a task to observe the perf counter periodically. When available memory drops below your threshold (or committed bytes exceeds your threshold), you can easily recycle the role instance:
RoleEnvironment.RequestRecycle();