mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 17:05:55 +08:00
|From: James J Greensky <jame.j.greensky@intel.com>
|Date: Wed, 5 Aug 2009 09:51:52 -0700 |Subject: [PATCH] Closed two major memory leaks for scripted objects | |Two major memory leaks for the scripted objects were fixed |- One leak had to do with remoting acrossing app domains. When a script and | its controlling agent communicate across an application boundary, it calls | functions on a stub proxy object that then invokes the remote method on | the object in the other app domain. These stub objects (two for each script) | were setup to have infinate lifetimes and were never being garbage collected. |- The second leak was the result of adding a scene object part instance method | to a scene event and never removing it. This cause the event's delegate list | to maintain a link to that object which is then never freed as the scene event | object is never destroyed. Patch applied, please direct feedback to me. Possible issue: Longtime idle scripts like vendors may fail.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
@@ -34,26 +35,23 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
using OpenSim.Region.ScriptEngine.Shared;
|
||||
using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
{
|
||||
public partial class ScriptBaseClass : MarshalByRefObject, IScript
|
||||
{
|
||||
private Dictionary<string, MethodInfo> inits = new Dictionary<string, MethodInfo>();
|
||||
private ScriptSponsor m_sponser;
|
||||
|
||||
// Object expires if we don't keep it alive
|
||||
// sponsor will be added on object load
|
||||
[SecurityPermissionAttribute(SecurityAction.Demand,
|
||||
Flags = SecurityPermissionFlag.Infrastructure)]
|
||||
public override Object InitializeLifetimeService()
|
||||
{
|
||||
ILease lease = (ILease)base.InitializeLifetimeService();
|
||||
if (lease.CurrentState == LeaseState.Initial)
|
||||
{
|
||||
lease.InitialLeaseTime = TimeSpan.Zero;
|
||||
// lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
|
||||
// lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
|
||||
// lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
|
||||
lease.InitialLeaseTime = TimeSpan.FromMinutes(1.0);
|
||||
lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
|
||||
lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
|
||||
}
|
||||
return lease;
|
||||
}
|
||||
@@ -66,7 +64,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public ScriptBaseClass()
|
||||
{
|
||||
m_Executor = new Executor(this);
|
||||
@@ -81,6 +78,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
inits[type] = mi;
|
||||
}
|
||||
}
|
||||
|
||||
m_sponser = new ScriptSponsor();
|
||||
}
|
||||
|
||||
private Executor m_Executor = null;
|
||||
@@ -112,6 +111,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
if (!inits.ContainsKey(api))
|
||||
return;
|
||||
|
||||
ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject);
|
||||
lease.Register(m_sponser);
|
||||
|
||||
MethodInfo mi = inits[api];
|
||||
|
||||
Object[] args = new Object[1];
|
||||
@@ -122,6 +124,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
m_InitialValues = GetVars();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
m_sponser.Close();
|
||||
}
|
||||
|
||||
public Dictionary<string, object> GetVars()
|
||||
{
|
||||
Dictionary<string, object> vars = new Dictionary<string, object>();
|
||||
|
||||
Reference in New Issue
Block a user