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