I have an ATL based ActiveX component (MyLib) that is used from within
classic ASP pages (created via Server.CreateObject).

Inside MyLib there is a custom class (MyCustomClass) that basically just
consists of several member variables that hold primitive data types (ints
and bools) along with several CComBSTR variables.

I want to expand MyLib so that it will create a new instance of a
MyCustomClass object and store it into an ASP session variable with the
user's context (tapped into using CComPtr<IScriptingContext>).

My concern, however, is that I do not know how (or even if) ASP will go
about cleaning up this object and I want to make sure I am not at risk for
leaking memory.

For example, here is pseudo code for what I want to accomplish from within
MyLib running in an ASP page:

MyCustomClass custClass = new MyCustomClass();

set values of custClass data members

using the methods provided by IScriptingContext, store this instance
(or a pointer of the instance) of custClass into the user's ASP session
under the session variable name "myCustomData"

Now my main questions and concerns are this:

1) Now say 20 minutes pass with no ASP activity for this user and ASP
decides its time to destory their session variables. What happens to the
instance of custClass? Does ASP call some method or do a "delete" on the
object store in there or what? I have a feeling that it does not, and this
would leave my custom class lingering in memory indefinately which would
cause a memory leak, right? Remember that custClass is not a ATL/COM object
itself - just a very simple class (reallly nothing more than a data
strucuture) to hold some values.

2) What is the best approach to use here so that when ASP times the session
out, I am certain that custClass gets deleted and its memory freed?

3) Ideally I would like to create an instance of custClass on the stack and
have it stored directly into the session object, rather than creating an
instanace in my ATL object (MyLib) and having it then store a pointer to
this instance in the ASP session. Is that possible? In other words I'd
like to store the object directly into the ASP session if I could.

Thanks in advance for your thoughts on this.

Steve

Re: How do I ensure ActiveX object is cleaned up when stored in ASP session? by Egbert

Egbert
Thu Jul 14 13:36:20 CDT 2005

"Steve Franks" <please@postreplyhere.com> wrote in message
news:b6adnWJ8-9IFAEvfRVn-jw@comcast.com...
>I have an ATL based ActiveX component (MyLib) that is used from within
>classic ASP pages (created via Server.CreateObject).
>
> Inside MyLib there is a custom class (MyCustomClass) that basically just
> consists of several member variables that hold primitive data types (ints
> and bools) along with several CComBSTR variables.

Hi Steve,

What you have, is a pointer to an interface. In theory, VB6 for instance,
can handle that very well. And in ASP it would become a VARIANT of type
VT_RECORD but still, I've never seen such a thing. You still must expose
that interface with methods for oleautomation so it becomes a valid '
object'. It's really the best thing to create a COM wrapper.

Second, ASP -will- destroy your COM object after 20 minutes. But do not
expect a good scalability. Your COM object -must- be marked for 'both'
threading (not apartment, other wise you will quickly see hick-ups and
locks) and even then, it uses a lot of resources which pick up memory during
20 minutes. So if you need a scalable webfarm, try to avoid a solution that
you are making now.

--
compatible web farm Session replacement for Asp and Asp.Net
http://www.nieropwebconsult.nl/asp_session_manager.htm


> I want to expand MyLib so that it will create a new instance of a
> MyCustomClass object and store it into an ASP session variable with the
> user's context (tapped into using CComPtr<IScriptingContext>).
>
> My concern, however, is that I do not know how (or even if) ASP will go
> about cleaning up this object and I want to make sure I am not at risk for
> leaking memory.
>
> For example, here is pseudo code for what I want to accomplish from within
> MyLib running in an ASP page:
>
> MyCustomClass custClass = new MyCustomClass();
>
> set values of custClass data members
>
> using the methods provided by IScriptingContext, store this instance
> (or a pointer of the instance) of custClass into the user's ASP session
> under the session variable name "myCustomData"
>
> Now my main questions and concerns are this:
>
> 1) Now say 20 minutes pass with no ASP activity for this user and ASP
> decides its time to destory their session variables. What happens to the
> instance of custClass? Does ASP call some method or do a "delete" on the
> object store in there or what? I have a feeling that it does not, and
> this would leave my custom class lingering in memory indefinately which
> would cause a memory leak, right? Remember that custClass is not a
> ATL/COM object itself - just a very simple class (reallly nothing more
> than a data strucuture) to hold some values.
>
> 2) What is the best approach to use here so that when ASP times the
> session out, I am certain that custClass gets deleted and its memory
> freed?
>
> 3) Ideally I would like to create an instance of custClass on the stack
> and have it stored directly into the session object, rather than creating
> an instanace in my ATL object (MyLib) and having it then store a pointer
> to this instance in the ASP session. Is that possible? In other words
> I'd like to store the object directly into the ASP session if I could.
>
> Thanks in advance for your thoughts on this.
>
> Steve
>
>