Since Workflow is a MBRO, it's instances live on the server and are accessed
remotely. You have to think about the behaviour you want here. Do you
really want all the Workflow objects to exist on the server, or do you want
to send them (Serializable) across the wire to the client? How long should
they exist on the server for? If they're going to be accessed remotely,
they need to exist at least as long as any calls may be made to them.
The default behaviour for controlling object lifetime in .NET is to use
"leases" (you may want to read up on this in MSDN if you aren't familiar
with it). I see you've disabled leases for WorkflowCollection (by returning
null from InitializeLifetimeService). If you're doing the same with
Workflow, then you potentially have objects that will live forever - and so
I'd expect your memory usage to keep going up.
You probably want to make use of remoting lifetime management (with leases),
as well as possibly having the client explicitly indicate when it's done
using the Workflow objects created by a call to EnumerateWorkflows. Or,
depending on exactly what you're trying to achieve, you might want to
consider redesigning the whole thing to only allocate objects when they are
needed and release them when they are no longer needed.
Rick
----- Original Message -----
From: "Pauline Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 12, 2004 3:01 PM
Subject: How to release the memory from a MarshbyRefObject object?
> Hi,
>
> I am trying to find out how to release the memory from a
> MarshByRefObject object.
> My c# application is window service. It gets call from another
> window service or remote window clients.
> In the EnumerateWorkflows method, I returns the arraylist of
> IWorkflow which is MarshByRefObject.
> If the client invoke 1000 EnumerateWorkflows calls, my window
> service memory will grow very large.
> Any suggestions as how my service can release some of the memory?
>
> THanks,
>
> Pauline
> -----------
> class WorkflowCollection : MarshalByRefObject, IWorkflowCollection
> {
> public override Object InitializeLifetimeService()
> {
> null;
> }
>
> public IWorkflow[] EnumerateWorkflows()
> {
> try
> {
> .
> .
> .
> ArrayList workflows = new ArrayList();
> foreach (DataRow row in ds.Tables
> ["workflow"].Rows )
> {
> IWorkflow newWorkflow = new Workflow
> (...) // IWorkflow is MarshByRefObject
> workflows.Add(newWorkflow);
> }
> return (IWorkflow[]) workflows.ToArray
> (typeof(IWorkflow));
> }
> catch (Exception e)
> {
> log.ErrWriteLine(string.Format
> ("WorkflowCollection:EnumerateWorkflow(): Caught {0}: {1}\n{2}",
> e.GetType(), e.Message,
> e.StackTrace));
> return null;
> }
>
> }
>
> }
> }
>
> ===================================
> This list is hosted by DevelopMentor� http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor� http://www.develop.com
Some .NET courses you may be interested in:
NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls
View archives and manage your subscription(s) at http://discuss.develop.com