Re: caching: Session state or Application state...



<spacehopper_man@xxxxxxxxx> wrote in message
news:1133218879.717974.319780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I'm considering ditching all use of Session state in favour of
> Application state.
>
> This is because - from what I can work out - it will be more memory
> efficient for me.

If your only sharing data at an application scope, and need no session
independence it makes sense! Thats a judgement call on your part. Be aware
that overloading any of the state objects can be a bad thing.

> I have three questions:
>
> 1) When is memory used for Session State freed (or essentially freed)?
> - if ever...

When the session ends and the systems decides that all objects now out of
scope can be freed and garbage collected, I dont recall there being a fixed
duration as to when this happens. When the garbage collector decides that
sufficient garbage has accumulated that it is efficient to do so, it
performs a collection to free some memory.

> 2) When is memory used in Application State (or essentially freed) - eg
> - if my cache item expires due to it reaching it's expiration time - is
> it freed immediately - or must the process wait for some cleanup job to
> run.

When a cached object expires, the ASP.NET process removes it behind the
scenes immediately unless an active request for that cache item is
different to the retrieved value at request time and it needs to be updated,
then it updates the object if its priority is high enouigh to merit keeping
it cached. However, the type of cahcing and the expiration policy can see
the cache object reacting in different ways, for example if your using
sliding expiration, or SQL cache invalidation. If you keep adding items
to the cache and it gets full (ie. the free cache memory is exhausted),
ASP.NET will automatically invalidate and removes the oldest, least used, or
lowest priority items from the cache, hence you may not see your object
behave as predictably as you think it might. You need to be aware of this
if your going to use it heavily. Its worth having a read of Alex Homes
excellent article on this:
http://www.devx.com/dotnet/Article/27865/1954?pf=true


> 3) does anyone know of any docs/articles on when *exactly* memory is
> made available when using the various caching techniques?

Not exactly, this is an easy read though and you can deduce when the memory
would be freed. Only tip I guess is to watch perfromance monitor to see
exactly whats happening.

http://msdn.microsoft.com/asp.net/archive/?pull=/library/en-us/dnvs05/html/cachingnt2.asp

also read about GC here

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt05.asp


> cheers very much,
> Oli.
>


--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director


.



Relevant Pages

  • Re: Cached memory never gets released
    ... Stock linux 2.4.26 kernel. ... Due to flash bug 3M of memory gets lost due to font memory getting lost ... The output of "free" cache number steadily grows. ... longer to exhaust all of system memory with the cache. ...
    (Linux-Kernel)
  • Re: Problem: Creating a raw binary string
    ... > While its true that a 64-bit cpu will move twice the data per instruction it ... > Memory bus width plays an important role here and unless it too is widened / ... You are forgetting the two levels of cache in the processor. ... The memory chips are addressed in Row col fashion. ...
    (alt.comp.lang.borland-delphi)
  • Re: Is Greenspun enough?
    ... Most OSes memory map executables directly from the file system so code doesn't pollute the file cache or swap space. ...
    (comp.lang.lisp)
  • Re: Superstitious learning in Computer Architecture
    ... Without a LOT of logic or some other better approach, re-executing the instructions requires re-decoding and it ties up the cache memory bus transferring more data as instructions than the instructions are working on. ... The concept of cache is fundamentally flawed in that it STILL restricts access to one word per clock cycle, when a single modern ALU can easily use 5 plus whatever is eaten up with instruction accesses. ... The size of an optimizing compiler is proportional to the SQUARE of the size of the language times the SQUARE of the complexity of the machine - because all interactions must be considered. ...
    (comp.arch.arithmetic)
  • Re: FPGA-based hardware accelerator for PC
    ... I know that in most cases the CPU ... that it contsins no cache, as BRAMs are too precious resources to be wasted ... The BRAMs are what define the opportunity, ... many threads with full associativity of memory lines using hashed MMU ...
    (comp.arch.fpga)