Hi,
I have webservice which holds a static variable.
I send my first message into the webservice and the static variable gets
a value. If I queried the webservice at a later time (say after 1 hour)
would the static variable still hold the same value, or would the code
be re-initialised and the static variable back to the default value:
//static variable is default 0
//Call webservice
//static variable is set to 1
//Call webservice 1 hour later
//What value is static variable?
My understanding of the webservice process space (in terms of static
vars) was that it matched a windows service, where a static variable
value persisted for the lifetime of the service.
Thanks in advance.
Steven
*** Sent via Developersdex http://www.developersdex.com ***
Jan 10 '08
19 23389
Ok, so it seems I do have a problem with this approach.
Each call to my webservice creates an instance of a dll but I don't
think this dll is ever cleaned up (memory wise).
Is the dll still managed memory in this scenario, or have I turned of
memory allocation with the IIS settings and the number of instance keeps
pilling up?
If I stop IIS, I get lots of lines of trace that I added to a destructor
(just for debug purposes) showing the class being destroyed.
Assuming this is the case, the only way this memory can be released is
by stopping the service or by activating the recycling again?
*** Sent via Developersdex http://www.developersdex.com ***
Each call to my webservice creates an instance of a dll
Do you really mean dll? How do you mean? Do you mean your web-service
loads a few other .NET assemblies? In which case, they will only get
loaded once per AppDomain (not over and over); but an assembly will
not (and cannot) be unloaded without tearing down the AppDomain.
If you mean object instances, then that shouldn't be a problem; if you
are seeing leak-like behavior, then verify you haven't added your
objects to something longer-lived... event subscriptions (especially
static/singleton etc subscriptions) are typical offenders here, but
other things (collections etc) are possible.
If you mean something more esoteric, you'll have to add detail to give
a meaningful reply...
It would also help if you indicated how you were monitoring the
memory; simple measures (taskman, for instance) can be deceptive...
Marc
One other thing... if you are using *static* variables, you probably
want to be very careful about thread synchronisation ; but this may
effectively serialize access to your service (i.e. one at a time,
please...).
If you can describe *what* you are doing with your static variables,
it might help shed light on your memory issue... personally I try to
avoid static state in services, except for configuration state loaded
(for example) once in a static ctor.
Marc
A call to my webservice creates an instance of my dll:
MyWebMethod()
{
MyDll x = new MyDll();
x.DoSomeStuff() ;
}
In the the dll, MyDll, I wrote a destructor to prove x is always
released. This writes out a line of trace when called. It's only written
out when I stop IIS from running.
Please note that I have turned off the recycling at IIS and I assume
this is causing the problem since turning it back on (say every minute)
I start seeing my destructor code being written out.
*** Sent via Developersdex http://www.developersdex.com ***
The static are used as a status.
For example.
Call to webservice sets static variable to Started state.
Next caller, this variable needs to be set to previous callers state.
The statics work as way for indicating the mode my service is (Not
Logged in, Started etc) so must be persisted.
*** Sent via Developersdex http://www.developersdex.com ***
If the static variable is just status, you should be fine (locking
aside...) - bigger problem is if you have a big collection in the
static fields - which will of course sit their consuming memory...
hence why I raised this in connection with your memory concerns.
Marc
Yup, my statics are protected with a lock, so I don't think there is any
threading issues here.
The main concern is why the memory is NOT being released for the dll.
*** Sent via Developersdex http://www.developersdex.com ***
Its the whole class instance that concerns me.
The static need to hang around, and I accept the memory will not be
released. But the class that I create using instance variables etc is
never cleaned up.
*** Sent via Developersdex http://www.developersdex.com ***
But the class that I create using instance variables etc is
never cleaned up.
Well, it should be. If it isn't, then you're code is almost certainly
placing those controls somewhere publicly visible. Either that, or you
are using session-state and haven't ended the session - in which case
yes: the instance of the service implementation (per client) will be
retained. That is the pain of session state (and one of the many
reasons that I never use stateful web-services...)
Marc
I am pretty sure I am not using the Session (for example I have no code
which says Session["blah"] = myObj;
I just have a simple webservice which creates an instance of a dll. This
dll is not released when I turn of IIS recycle.
As a workaround, I now have a static counter and when it reaches
MAX_CALLS, run the GC :|
It cleans the memory up for me now.
*** Sent via Developersdex http://www.developersdex.com *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joe Narissi |
last post by:
I know how to create and use static constructors, but is there a such thing
as a static destructor?
If not, then how do you deallocate memory intialized in the static
constructor?
Thanks in advance,
Joe
|
by: xzzy |
last post by:
Using ASP.net, C# and a static class, does the following from MSDN mean:
1. a static hashtable would only live during the session and end when the
session ends
2. there would be a different static hashtable for each session
++ from MSDN ++
|
by: Jack |
last post by:
Thanks.
|
by: junw2000 |
last post by:
When I define a static variable, where is the memory allocated for the
static variable?
Thanks.
Jack
|
by: Morgan Cheng |
last post by:
In the book *Programming C#* 4th editionby Jesse Liberty, it reads
"Actually, the CLR guarantees to start running the static constructor
before anything else is done with your class. However, it only
guarantees to *start* running the static constructor; it doesn't
actually guarantee to *finish* running it." Page 82, Chap 4 Classes and
Objects.
If it is true, then it is possible that some static fields are not
initialized (by static...
| |
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in C# in some
way? Or maybe no, because it is similar to a global variable (with its
scope restricted) which C# is dead against?
Zytan
|
by: Jess |
last post by:
Hello,
I learned that there are five kinds of static objects, namely
1. global objects
2. object defined in namespace scope
3. object declared static instead classes
4. objects declared static inside functions (i.e. local static
objects)
5. objects declared at file scope.
|
by: Pramod |
last post by:
Hello to all of you,
I want to know that what's the use to create static object.
Thanks You
Pramod Sahgal
|
by: mdh |
last post by:
Hi all,
When I try and initialize this static array, as in:
void itoa_recursively(int n, char *s){
static char *p = s;
it fails, yet this:
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |