My background is with web application (PHP), you requested a page, run your code to handle that request and the the process is over, you generally don’t have to worry to much about un-setting variables and things like that since the process is done once the page loads.
Looking into some desktop application development with C#, just curious how this differs from the web. Say I launch the program, a user does some actions, the program is not done like a web app would be, so what do you do differently? Do you have to be conscious about un-setting variables and things when finished with them to prevent memory waste?
Most web programming is stateless. With desktop programming, your individual functions are usually stateless. You’ll pass in all of the information you need as parameters, and get everything you need back out. However, the main program will store some state.
Rich Internet Applications often keep state, and some websites use the HTML content itself as state, and update it through Javascript, etc.
The User Interface of a desktop programming is similar. The edit and various other controls store some state. You’ll store some global variables for things like user settings, which you can think of similar to session variables. Running an application is similar to having a session.
Desktop programming is also highly event based. Quite often, a program will be sitting there waiting for the user to click on a button or something. So, usually we’re talking Windows and event handlers. You might be familiar with these in Javascript.
C# does garbage collection, so you don’t really have to worry about deleting variables. As soon as they go out of scope, they’re usually cleaned up. Global class variables won’t be cleaned up until the application shuts down, and you don’t have to clear variables when you shut down the application. They’ll all disappear when the process ends, just like PHP.
Don’t use global variables (which don’t go out of scope) inside a function, when you should be using local ones.
PHP has local and global variables too, so this should be familiar territory.