Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
QuestionDirect instantiation of Bitmap from unsafe memory Pin
Florian Storck6-Jun-06 4:10
Florian Storck6-Jun-06 4:10 
QuestionGet file that spawned the application. Pin
cmarcus6-Jun-06 4:01
cmarcus6-Jun-06 4:01 
AnswerRe: Get file that spawned the application. Pin
Stephan Samuel6-Jun-06 4:08
Stephan Samuel6-Jun-06 4:08 
GeneralRe: Get file that spawned the application. Pin
cmarcus6-Jun-06 5:58
cmarcus6-Jun-06 5:58 
AnswerRe: Get file that spawned the application. Pin
J4amieC6-Jun-06 4:11
J4amieC6-Jun-06 4:11 
AnswerRe: Get file that spawned the application - New Problem Pin
cmarcus6-Jun-06 8:44
cmarcus6-Jun-06 8:44 
QuestionShared Add-in for Excel 2003 and Garbage Collector Pin
Kadur6-Jun-06 3:55
Kadur6-Jun-06 3:55 
QuestionObject lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 3:54
User 66586-Jun-06 3:54 
Hi everybody

I'm currently experimenting with design patterns, one of them is the design pattern. First some code:

This will init my application, it will init itself then by switching from state to state

static void Main(string[] args)
{
	ScreenInitState startState = ScreenInitState.GetInstance();
	Console.WriteLine("All states exited");

	Console.WriteLine("Press any key to exit.");
	Console.ReadKey();
}


Here we switch from state to state

abstract class InitState
{
	protected void Switch(InitState state, bool bStopSelf)
	{
		if (bStopSelf)
			Stop();
	}

	abstract protected void Stop();
}

class ScreenInitState : InitState
{
	private ScreenInitState()
	{
		// init screen here and go to next state

		Switch(InputInitState.GetInstance(), true);
	}

	// ...
}

class InputInitState : InitState
{
	private InputInitState()
	{
		// init input here and go to next state
		
		Switch(SoundInitState.GetInstance(), true);
	}

	// ...
}


So the app starts like this:
Main -> SreenInitState -> InputInitState -> SoundInitState -> ...

Now when I'm in the last state, do all previous states still exist in memory or are the collected by the GC? Though this pattern is very useful I'm concerned about memory usage here. Does anyone know what happens to the objects during runtime?

regards

-- modified at 9:54 Tuesday 6th June, 2006

modified 12-Sep-18 21:01pm.

AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Stephan Samuel6-Jun-06 4:03
Stephan Samuel6-Jun-06 4:03 
GeneralRe: Object lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 4:07
User 66586-Jun-06 4:07 
GeneralRe: Object lifetime, GC and the State Pattern Pin
Stephan Samuel6-Jun-06 6:53
Stephan Samuel6-Jun-06 6:53 
GeneralRe: Object lifetime, GC and the State Pattern Pin
User 66586-Jun-06 7:51
User 66586-Jun-06 7:51 
AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Guffa6-Jun-06 4:23
Guffa6-Jun-06 4:23 
GeneralRe: Object lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 4:28
User 66586-Jun-06 4:28 
AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Guffa6-Jun-06 8:50
Guffa6-Jun-06 8:50 
QuestionString manipulation performance issue Pin
sjembek6-Jun-06 3:37
sjembek6-Jun-06 3:37 
AnswerRe: String manipulation performance issue [modified] Pin
sathish s6-Jun-06 3:48
sathish s6-Jun-06 3:48 
GeneralRe: String manipulation performance issue [modified] Pin
sjembek6-Jun-06 4:04
sjembek6-Jun-06 4:04 
AnswerRe: String manipulation performance issue Pin
Stefan Troschuetz6-Jun-06 3:50
Stefan Troschuetz6-Jun-06 3:50 
AnswerRe: String manipulation performance issue [modified] Pin
Guffa6-Jun-06 5:20
Guffa6-Jun-06 5:20 
QuestionControlled Focus event - textBox Pin
conrado76-Jun-06 3:26
conrado76-Jun-06 3:26 
AnswerRe: Controlled Focus event - textBox Pin
NaNg152416-Jun-06 3:34
NaNg152416-Jun-06 3:34 
GeneralRe: Controlled Focus event - textBox Pin
conrado76-Jun-06 3:45
conrado76-Jun-06 3:45 
QuestionException Pin
sanmech6-Jun-06 3:25
sanmech6-Jun-06 3:25 
QuestionDrag&Drop listview subitem? Pin
Dominik Reichl6-Jun-06 3:16
Dominik Reichl6-Jun-06 3:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.