|
|
|
date: Fri, 4 Jul 2008 03:07:03 -0700,
group: microsoft.public.sharepoint.windowsservices.development
back
RE: SPItemEventProperties.Dispose()
{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang2052\f0\fs20 Hi Christopherki,
\par
\par Regarding on this issue, is it the same with the following "Dispose warning in Central Admin" thread you posted?
\par
\par Subject: Dispose warning i Central Admin
\par Newsgroups: microsoft.public.sharepoint.windowsservices.development
\par
\par As for the object disposing, as far as I know, for those system(built-in) managed objects(such as the SPxxxPriperties event parameter passed in event handler), they're handled by system, and we will not need to do additional disposing code with it. What we need to take care more in sharepoint code are those "SPSite", "SpWeb" objects we manually created.
\par
\par Here is a blog article about the disposing pattern in sharepoint development code:
\par
\par #SharePoint 2007 and WSS 3.0 Dispose Patterns by Example
\par http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx
\par
\par Sincerely,
\par
\par Steven Cheng
\par
\par Microsoft MSDN Online Support Lead
\par
\par
\par Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
\par
\par ==================================================
\par Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
\par
\par Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support
\par Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support
\par professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations
\par that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx.
\par ==================================================
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par \pard\li720 --------------------
\par From: =?Utf-8?B?Q2hyaXN0b3BoZXI=?= <Christopherki@nospam.nospam>
\par Subject: SPItemEventProperties.Dispose()
\par Date: Fri, 4 Jul 2008 03:07:03 -0700
\par
\par
\par During development of my code I discovered that under certain circumstances I
\par was not disposing of SPSite. Digging into the stack trace I found that the
\par offending line indicated the SPItemEventProperties.ListItem property. Since
\par this is Microsoft code, I was a bit confused.
\par
\par Using .NET reflector I discovered that when one accesses the ListItem, a new
\par SPSite and SPWeb may be created. An internal flag is also set to indicated if
\par the objects were created before or after the SPItemEventProperties object was
\par created. From what I understand, we can call Dispose() no matter what, if the
\par SPSite and SPWeb object was created by SharePoint, the flag will prevent them
\par from being disposed when we call Dispose().
\par
\par In my code I have now wrapped the properties parameter with a using
\par statement so that Dispose() will be called when leaving the event handler.
\par This seems to have done the trick.
\par
\par Is this the correct and supported way of doing things?
\par
\par I wish this pattern had been used in more parts of SharePoint. That way if
\par we see something implementing IDispose and we are finished with it, we could
\par call it. If SharePoint isn't finished with it, you kan keep it around for how
\par long you want.
\par \pard
\par
\par }
date: Mon, 07 Jul 2008 03:33:20 GMT
author: (Steven Cheng [MSFT])
RE: SPItemEventProperties.Dispose()
The other posting about central admin is mainly for your information. I just
discovered it when looking for something else.
This whole thing with dispose in SharePoint is a complete mess! Looking at
the SPItemEventProperties, it may call OpenWeb() when you access the ListItem.
The OpenWeb() may create a new SPSite and SPWeb object depending on the
context it's being run in. Since 'it depends' it's very hard to write code
that will work for all scenarios.
If the event handlers are being called as a result of page interaction, you
are probably good. But if they run as a result of a command line program, you
may have to dispose things you would not normally have to.
Chris
"Steven Cheng [MSFT]" wrote:
> Hi Christopherki,
>
> Regarding on this issue, is it the same with the following "Dispose warning
> in Central Admin" thread you posted?
>
> Subject: Dispose warning i Central Admin
> Newsgroups: microsoft.public.sharepoint.windowsservices.development
>
> As for the object disposing, as far as I know, for those system(built-in)
> managed objects(such as the SPxxxPriperties event parameter passed in event
> handler), they're handled by system, and we will not need to do additional
> disposing code with it. What we need to take care more in sharepoint code
> are those "SPSite", "SpWeb" objects we manually created.
>
> Here is a blog article about the disposing pattern in sharepoint
> development code:
>
> #SharePoint 2007 and WSS 3.0 Dispose Patterns by Example
> http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0
> -dispose-patterns-by-example.aspx
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> --------------------
> From: =?Utf-8?B?Q2hyaXN0b3BoZXI=?= <Christopherki@nospam.nospam>
> Subject: SPItemEventProperties.Dispose()
> Date: Fri, 4 Jul 2008 03:07:03 -0700
>
>
> During development of my code I discovered that under certain circumstances
> I
> was not disposing of SPSite. Digging into the stack trace I found that the
> offending line indicated the SPItemEventProperties.ListItem property. Since
> this is Microsoft code, I was a bit confused.
>
> Using .NET reflector I discovered that when one accesses the ListItem, a
> new
> SPSite and SPWeb may be created. An internal flag is also set to indicated
> if
> the objects were created before or after the SPItemEventProperties object
> was
> created. From what I understand, we can call Dispose() no matter what, if
> the
> SPSite and SPWeb object was created by SharePoint, the flag will prevent
> them
> from being disposed when we call Dispose().
>
> In my code I have now wrapped the properties parameter with a using
> statement so that Dispose() will be called when leaving the event handler.
> This seems to have done the trick.
>
> Is this the correct and supported way of doing things?
>
> I wish this pattern had been used in more parts of SharePoint. That way if
> we see something implementing IDispose and we are finished with it, we
> could
> call it. If SharePoint isn't finished with it, you kan keep it around for
> how
> long you want
date: Mon, 7 Jul 2008 01:08:01 -0700
author: Christopher am
RE: SPItemEventProperties.Dispose()
{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang2052\f0\fs20 Hi Chris,
\par
\par Thanks for your sincere feedback.
\par Yes, I can understand your feeling that the sharepoint sdk and development interfaces are not quite easy to followup sometimes since the fundamental object model is quite complex. For many issues, we sometimes also have to consult the dev team for more information. Anyway, you're also welcome to post some comments to the dev team. There is team blog of the sharepoint team:
\par
\par #Microsoft SharePoint Team Blog
\par http://blogs.msdn.com/sharepoint/
\par
\par I think they'll be glad to hear more from community users.
\par
\par Sincerely,
\par
\par Steven Cheng
\par
\par Microsoft MSDN Online Support Lead
\par
\par
\par Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com.
\par
\par ==================================================
\par Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
\par
\par ==================================================
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par \pard\li720 --------------------
\par From: =?Utf-8?B?Q2hyaXN0b3BoZXI=?= <Christopherki@nospam.nospam>
\par References: <8QKU6I#3IHA.1624@TK2MSFTNGHUB02.phx.gbl>
\par Subject: RE: SPItemEventProperties.Dispose()
\par Date: Mon, 7 Jul 2008 01:08:01 -0700
\par
\par
\par The other posting about central admin is mainly for your information. I just
\par discovered it when looking for something else.
\par
\par This whole thing with dispose in SharePoint is a complete mess! Looking at
\par the SPItemEventProperties, it may call OpenWeb() when you access the ListItem.
\par
\par The OpenWeb() may create a new SPSite and SPWeb object depending on the
\par context it's being run in. Since 'it depends' it's very hard to write code
\par that will work for all scenarios.
\par
\par If the event handlers are being called as a result of page interaction, you
\par are probably good. But if they run as a result of a command line program, you
\par may have to dispose things you would not normally have to.
\par
\par Chris
\par
\par "Steven Cheng [MSFT]" wrote:
\par
\par > Hi Christopherki,
\par >
\par > Regarding on this issue, is it the same with the following "Dispose warning
\par > in Central Admin" thread you posted?
\par >
\par > Subject: Dispose warning i Central Admin
\par > Newsgroups: microsoft.public.sharepoint.windowsservices.development
\par >
\par > As for the object disposing, as far as I know, for those system(built-in)
\par > managed objects(such as the SPxxxPriperties event parameter passed in event
\par > handler), they're handled by system, and we will not need to do additional
\par > disposing code with it. What we need to take care more in sharepoint code
\par > are those "SPSite", "SpWeb" objects we manually created.
\par >
\par > Here is a blog article about the disposing pattern in sharepoint
\par > development code:
\par >
\par > #SharePoint 2007 and WSS 3.0 Dispose Patterns by Example
\par > http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0
\par > -dispose-patterns-by-example.aspx
\par >
\par > Sincerely,
\par >
\par > Steven Cheng
\par >
\par > Microsoft MSDN Online Support Lead
\par >
\par
\par }
date: Wed, 09 Jul 2008 05:53:14 GMT
author: (Steven Cheng [MSFT])
|
|