JasonDavis
JasonDavis

Reputation: 48983

From web application to Desktop applications

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?

Upvotes: 2

Views: 1468

Answers (3)

Marcus Adams
Marcus Adams

Reputation: 53880

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.

Upvotes: 1

Kumar
Kumar

Reputation: 1015

Yes you need to worry. Mostly you may have to worry about unmananged objects as managed objects are handled by the Garbage Collector.

Upvotes: 1

Jason Meckley
Jason Meckley

Reputation: 7591

the short answer is yes. you would need to unregister event handlers, dispose of objects, remove strong references, etc. how this looks depends on how the code is structured.

Upvotes: 2

Related Questions