-2

I refer to a previous post Tridion 2009 Template Publishing Failure where I explained that our system was crashing apparently randomly during mass-publishing.

We're using XSLTMediator & all our templates are based around the TemplateBase solution

I've been advised that the error may be related to Garbage Collection / COM+ - I think it's a bit of a red herring, the TemplateBase solution implements IDisposable explicitly which should take care of all GC/COM+ nastiness? (unlike in the VBScript days of Set obj = Nothing to avoid memory leaks)!

Thanks.

Community
  • 1
  • 1
mpaton
  • 789
  • 3
  • 14
  • 2
    Can you please provide the error message from the event viewer logs? Also, is your question "how does Tridion publishing do garbage collection or how does each template get disposed?" – Nickoli Roussakov Jun 22 '12 at 12:16
  • 2
    Declaring IDisposable will not fix anything automatically. Your template/mediator code will have to implement Dispose **correctly** and close any resources it may be holding on to. You can consider calling .Close() the modern day equivalent of setting an object to Nothing. But all those are just statements, what is your question? – Frank van Puffelen Jun 22 '12 at 12:28
  • The mediator code is actually the XsltMediator (which doesn't implement `IDisposable` itself directly). In any case there are no unmanaged resources to worry about so the GC should be doing its job correctly? The TemplateBase does implement it which should be sufficient? I'm not sure what my question is, as I'm not convinced this problem is down to not implementing `IDisposable` – mpaton Jun 22 '12 at 13:36
  • I would be interested to know as a matter of course what the best practice is for implementing GC, and how Tridion itself disposes of templates if someone would be good enough to describe it! – mpaton Jun 22 '12 at 13:38

2 Answers2

2

It sounds like you need to do some in-depth debugging. One source of high quality information on this topic is Tess Ferrandez' blog

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56
-2

Here some considerations.

1) Use Marshal.ReleaseComObject to release the Tridion COM Objects but not just once call it until the references counter reaches 0.

while (Marshal.ReleaseComObject(component) > 0);

2) Don't pass COM Objects as parameters in functions.

3) Don't declare or avoid as much as you can to declare COM objects as fields in your class.

4) Consider using WeakReferences. A weak reference will mark your object immediately as ready for GC. Since the .Net GC runs in a background thread and we don't know exactly when it will be executed always add a null checking in all your weak references to make sure that your objects are still alive before you use it, in case it is already collected you will need to instantiate the weak reference again.

Eric Huiza
  • 393
  • 1
  • 4
  • The XSLTMediator is used with modular templating, so the API that will be in use is TOM.NET, which isn't going to hand you a RCW. Even if it did, using Marshal.FinalReleaseComObject() would save you having to code that loop yourself. Weak References aren't going to help you much in this scenario. If you need the object again, just keep hold of it with a strong reference during the lifetime of your template. Really! Weak references might make sense if you were pushing objects into some sort of long-lived cache, but why would you? – Dominic Cronin Jun 25 '12 at 19:48
  • TOM.NET objects like Engine, Session, still use interops behind the scenes so passing them to the XSLT Mediator as part of an extension object might cause memory leaks. In my experience passing objects between one technology to another like .Net and COM (MSXML Parser) can cause memory leaks that is why Weak References come into the picture forcing the release of it. – Eric Huiza Jun 25 '12 at 21:31
  • But a weak reference doesn't force the release of anything. If your strong references go out of scope, that has the same effect. A weak reference is only interesting if you deliberately want to keep an object "reachable" (but are prepared to let it be disposed, and deal with the consequences.) This probably isn't the scenario in a template. – Dominic Cronin Jun 25 '12 at 21:56