What is the best way to cleanup the resources used by a Crystal Reports ReportDocument object?

霸气de小男生 提交于 2019-12-05 00:52:58

Well, according to this, "Close() ... release[s] the memory that is used by the report." That would indicate that Close() calls Dispose(), so it would be redundant to have both a using statement and Close().

Fooksie

While there's a great deal of information available on the web relating to the proper use of memory and the corresponding cleanup of used memory when tasks are complete, at MSDN:IDisposable.Dispose or Stackoverflow:Disposing and Setting to null for example. This gives rise to the prevailing coding convention that if you can call Dispose, then do so.

This convention holds true for objects like FileStreams and SqlDataReader (among others) where you have both Close and Dispose methods, and calling Dispose calls the Close.

What I didn't take into account was "The Crystal Factor". Like them or loathe them, they do things...differently. After a LOT more searching online in the second reply to this SAP SDN article, a SAP employee seems to post the code of the Close method. As you can see, after clearing and disposing all the elements that comprise the ReportDocument object, it calls the ReportDocument.Dispose method as well.

Despite all that, and without knowing how the Dispose method is implemented (properly you would presume as the code does work in its present form), you should code to the proper convention and call the Dispose method or declare it in a Using statement. Just suppress the CA warning.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!