diff options
author | Melanie | 2009-08-06 22:03:20 +0100 |
---|---|---|
committer | Melanie | 2009-08-06 22:03:20 +0100 |
commit | 91f6898b26caa8f74533dbd90478cf4103251abe (patch) | |
tree | 0ee8d1b94c3f0667d32cbf56043fd021fc8d8b73 /OpenSim/Region/ScriptEngine/Shared/Api/Runtime | |
parent | Merge branch 'master' of ssh://melanie@opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-91f6898b26caa8f74533dbd90478cf4103251abe.zip opensim-SC-91f6898b26caa8f74533dbd90478cf4103251abe.tar.gz opensim-SC-91f6898b26caa8f74533dbd90478cf4103251abe.tar.bz2 opensim-SC-91f6898b26caa8f74533dbd90478cf4103251abe.tar.xz |
|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 'OpenSim/Region/ScriptEngine/Shared/Api/Runtime')
4 files changed, 26 insertions, 35 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs index 2501752..7f67599 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs | |||
@@ -35,7 +35,7 @@ using log4net; | |||
35 | 35 | ||
36 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | 36 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase |
37 | { | 37 | { |
38 | public class Executor : MarshalByRefObject | 38 | public class Executor |
39 | { | 39 | { |
40 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 40 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | 41 | ||
@@ -89,26 +89,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
89 | initEventFlags(); | 89 | initEventFlags(); |
90 | } | 90 | } |
91 | 91 | ||
92 | /// <summary> | ||
93 | /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class) | ||
94 | /// </summary> | ||
95 | /// <returns></returns> | ||
96 | public override Object InitializeLifetimeService() | ||
97 | { | ||
98 | //m_log.Debug("Executor: InitializeLifetimeService()"); | ||
99 | // return null; | ||
100 | ILease lease = (ILease)base.InitializeLifetimeService(); | ||
101 | |||
102 | if (lease.CurrentState == LeaseState.Initial) | ||
103 | { | ||
104 | lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1); | ||
105 | // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); | ||
106 | // lease.RenewOnCallTime = TimeSpan.FromSeconds(2); | ||
107 | } | ||
108 | return lease; | ||
109 | } | ||
110 | |||
111 | |||
112 | public scriptEvents GetStateEventFlags(string state) | 92 | public scriptEvents GetStateEventFlags(string state) |
113 | { | 93 | { |
114 | //m_log.Debug("Get event flags for " + state); | 94 | //m_log.Debug("Get event flags for " + state); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 9068634..753ca55 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -32,7 +32,7 @@ using LSLInteger = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | |||
32 | 32 | ||
33 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | 33 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase |
34 | { | 34 | { |
35 | public partial class ScriptBaseClass : MarshalByRefObject | 35 | public partial class ScriptBaseClass |
36 | { | 36 | { |
37 | // LSL CONSTANTS | 37 | // LSL CONSTANTS |
38 | public static readonly LSLInteger TRUE = new LSLInteger(1); | 38 | public static readonly LSLInteger TRUE = new LSLInteger(1); |
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>(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs index a2da14e..977ac30 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs | |||
@@ -32,15 +32,19 @@ using System.Text; | |||
32 | 32 | ||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Api.Runtime | 33 | namespace OpenSim.Region.ScriptEngine.Shared.Api.Runtime |
34 | { | 34 | { |
35 | [Serializable] | ||
36 | public class ScriptSponsor : MarshalByRefObject, ISponsor | 35 | public class ScriptSponsor : MarshalByRefObject, ISponsor |
37 | { | 36 | { |
38 | // In theory: I execute, therefore I am. | 37 | private bool m_closed = false; |
39 | // If GC collects this class then sponsorship will expire | 38 | |
40 | public TimeSpan Renewal(ILease lease) | 39 | public TimeSpan Renewal(ILease lease) |
41 | { | 40 | { |
42 | return TimeSpan.FromMinutes(2); | 41 | if (!m_closed) |
42 | return lease.InitialLeaseTime; | ||
43 | return TimeSpan.FromTicks(0); | ||
43 | } | 44 | } |
45 | |||
46 | public void Close() { m_closed = true; } | ||
47 | |||
44 | #if DEBUG | 48 | #if DEBUG |
45 | // For tracing GC while debugging | 49 | // For tracing GC while debugging |
46 | public static bool GCDummy = false; | 50 | public static bool GCDummy = false; |