   [.net] Disposing unmanaged resources in anonymous methods
  This is a tricky one:I have a class "EffectParameter" that is used to wrap the necessary information to bind a value to a DirectX shader parameter. Since some of these values have to be passed each frame, this class generates an anonymous method to bind the effect parameter to the dynamic value (so this method runs each frame).Howewer, when setting a new texture, a new EffectParameter object is generated and it replaces the previous one.The problem is that somewhere the anonymous method must still be referencing the Texture value and each time the texture is updated, there will be a memory leak.This is the method that generates the anonymous delegate:public static EffectParameter CreateCustomParameter(String varName, Effect effect, Texture value)   {  EffectHandle eH = effect.GetParameter(null, varName);  Update update = delegate(EffectParameter fxParam)  { fxParam.ownerEffect.SetValue(eH, value);  };  return new EffectParameter(varName, effect, update);   }I tried adding fxParam.value = value; into the anonymous method so to call Dispose() on that but it doesn't work. The anonymous one still must have some reference to the (Texture) value. In fact SlimDX when exiting says that there still are some objects alive.So, how can I get rid of that? There doesn't seem to be a .Dispose() on the update delegate.Thanks in advance.   
  Are you sure there is a memory leak? As soon as that EffectParameter is orphaned it will be eligible for collection. Holding a reference to a texture wont stop it being collected.You say there "will" be a memory leak but I'd test that first and confirm it before worrying about solving a problem that potentially doesn't exist.   