c# - Do static string variables occupy memory space even when null? -


my requirement pass parameters function page. considered 2 ways of doing - 1)sessions , 2) query strings.

sessions known increase load on server apposed query strings.

this way extracting parameter values url(after using query string)

static string para1 ; static string para2;   string[] parts = urlstring.split((new string[] { "?para1=", "&&para2="}), stringsplitoptions.none);   para1 = parts[1];   para2= parts[2]; 

do these strings results in loading memory if assign them null after use? using session better query strings in terms of memory allocation , server performance.

i don't think memory consumption main criteria upon decide whether use query string parameters or session variables. in example, variables static anyway memory consumption should not dependent on number of users. please note static variables can have various unexpected effects in web application shared between users.

in general, i'd prefer using query string parameters transmit data page. query string parameters scoped request, available requested page whereas session variables can accessed page.

also, memory consumed query string parameters freed automatically after request whereas need remove session variables if don't need them anymore if want efficient regards memory consumption. sure, session time out if user not active anymore, depending on configuration might result in wasting memory half hour.

no rule without exceptions: i'd use session variables instead of query string parameters if 1 of following conditions met:

  1. the data security critical: session variables stored on server whereas query string parameters transmitted client , visible in browser.
  2. if large amount of data transmitted other page more efficient keep data on server. in browsers there limit on length of query string, cannot use this.
  3. the data used in application (widely in "almost every page") query string parameters had repeated on , on again.

Comments