diff options
|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.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs index 964fe4c..d119a77 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Runtime.Remoting; | ||
29 | using System.Runtime.Remoting.Lifetime; | 30 | using System.Runtime.Remoting.Lifetime; |
30 | using System.Security.Permissions; | 31 | using System.Security.Permissions; |
31 | using System.Threading; | 32 | using System.Threading; |
@@ -34,26 +35,23 @@ using System.Collections; | |||
34 | using System.Collections.Generic; | 35 | using System.Collections.Generic; |
35 | using OpenSim.Region.ScriptEngine.Interfaces; | 36 | using OpenSim.Region.ScriptEngine.Interfaces; |
36 | using OpenSim.Region.ScriptEngine.Shared; | 37 | using OpenSim.Region.ScriptEngine.Shared; |
38 | using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; | ||
37 | 39 | ||
38 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | 40 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase |
39 | { | 41 | { |
40 | public partial class ScriptBaseClass : MarshalByRefObject, IScript | 42 | public partial class ScriptBaseClass : MarshalByRefObject, IScript |
41 | { | 43 | { |
42 | private Dictionary<string, MethodInfo> inits = new Dictionary<string, MethodInfo>(); | 44 | private Dictionary<string, MethodInfo> inits = new Dictionary<string, MethodInfo>(); |
45 | private ScriptSponsor m_sponser; | ||
43 | 46 | ||
44 | // Object expires if we don't keep it alive | ||
45 | // sponsor will be added on object load | ||
46 | [SecurityPermissionAttribute(SecurityAction.Demand, | ||
47 | Flags = SecurityPermissionFlag.Infrastructure)] | ||
48 | public override Object InitializeLifetimeService() | 47 | public override Object InitializeLifetimeService() |
49 | { | 48 | { |
50 | ILease lease = (ILease)base.InitializeLifetimeService(); | 49 | ILease lease = (ILease)base.InitializeLifetimeService(); |
51 | if (lease.CurrentState == LeaseState.Initial) | 50 | if (lease.CurrentState == LeaseState.Initial) |
52 | { | 51 | { |
53 | lease.InitialLeaseTime = TimeSpan.Zero; | 52 | lease.InitialLeaseTime = TimeSpan.FromMinutes(1.0); |
54 | // lease.InitialLeaseTime = TimeSpan.FromMinutes(1); | 53 | lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); |
55 | // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); | 54 | lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); |
56 | // lease.RenewOnCallTime = TimeSpan.FromSeconds(2); | ||
57 | } | 55 | } |
58 | return lease; | 56 | return lease; |
59 | } | 57 | } |
@@ -66,7 +64,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
66 | } | 64 | } |
67 | #endif | 65 | #endif |
68 | 66 | ||
69 | |||
70 | public ScriptBaseClass() | 67 | public ScriptBaseClass() |
71 | { | 68 | { |
72 | m_Executor = new Executor(this); | 69 | m_Executor = new Executor(this); |
@@ -81,6 +78,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
81 | inits[type] = mi; | 78 | inits[type] = mi; |
82 | } | 79 | } |
83 | } | 80 | } |
81 | |||
82 | m_sponser = new ScriptSponsor(); | ||
84 | } | 83 | } |
85 | 84 | ||
86 | private Executor m_Executor = null; | 85 | private Executor m_Executor = null; |
@@ -112,6 +111,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
112 | if (!inits.ContainsKey(api)) | 111 | if (!inits.ContainsKey(api)) |
113 | return; | 112 | return; |
114 | 113 | ||
114 | ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); | ||
115 | lease.Register(m_sponser); | ||
116 | |||
115 | MethodInfo mi = inits[api]; | 117 | MethodInfo mi = inits[api]; |
116 | 118 | ||
117 | Object[] args = new Object[1]; | 119 | Object[] args = new Object[1]; |
@@ -122,6 +124,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
122 | m_InitialValues = GetVars(); | 124 | m_InitialValues = GetVars(); |
123 | } | 125 | } |
124 | 126 | ||
127 | public void Close() | ||
128 | { | ||
129 | m_sponser.Close(); | ||
130 | } | ||
131 | |||
125 | public Dictionary<string, object> GetVars() | 132 | public Dictionary<string, object> GetVars() |
126 | { | 133 | { |
127 | Dictionary<string, object> vars = new Dictionary<string, object>(); | 134 | Dictionary<string, object> vars = new Dictionary<string, object>(); |