A Review question from the Microsoft book(exam 70-536)

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

I'm reading a book from Microsoft Press (exam 70-536) and there is some
Review questions after each chaper.
Here is the question "Which command would you use to close the application
domain in the following code sample."

AppDomain d = AppDomain.CreateDomain("New Domain");
d.ExecuteAssemblyByName("MyAssembly");

A. d. DomainUnload()
B. d = null
C. d.Unload()
D. AppDomain.Unload(d)

The right answer according to the book is B and D.
I have guessed only at D because I can't find why B is also included in the
right answer.
Because of the nature of the question I also got the impression that only
one answer is correct.

//Tony
 
Tony Johansson said:
Hi!

I'm reading a book from Microsoft Press (exam 70-536) and there is some
Review questions after each chaper.
Here is the question "Which command would you use to close the application
domain in the following code sample."

AppDomain d = AppDomain.CreateDomain("New Domain");
d.ExecuteAssemblyByName("MyAssembly");

A. d. DomainUnload()
B. d = null
C. d.Unload()
D. AppDomain.Unload(d)

The right answer according to the book is B and D.
I have guessed only at D because I can't find why B is also included in
the right answer.
Because of the nature of the question I also got the impression that only
one answer is correct.

//Tony

Sort of a trick answer, IMHO, as it's a throwback to C++ manual garbage
collection when we were taught to "null the pointer" once we were through
with an object created on the heap and had released the allocated memory.
The idea was: don't leave a pointer hanging around that contains an address
you no longer control.

I'm sure you know that d (from your example) holds the address of the
AppDomain object, and that d = null; removes the only reference to that
object (assuming no others), making it eligible for automatic garbage
collection.

That's my guess why they say B is correct as well.
 
PvdG42 said:
Sort of a trick answer, IMHO, as it's a throwback to C++ manual garbage
collection when we were taught to "null the pointer" once we were through
with an object created on the heap and had released the allocated memory.
The idea was: don't leave a pointer hanging around that contains an
address you no longer control.

I'm sure you know that d (from your example) holds the address of the
AppDomain object, and that d = null; removes the only reference to that
object (assuming no others), making it eligible for automatic garbage
collection.

That's my guess why they say B is correct as well.

I see what you mean but assume that I create a person object from the Person
class like this
Person myPerson = new Person(add some data here to the c-tor);

I never used to set null to the object like this
myPerson=null;
So If I don't do this will this object myPerson never be garbage collected
because you will still have a reference.

So do you mean that when I'm finish with an object assign null to the object

//Tony
 
Tony Johansson said:
Hi!

I'm reading a book from Microsoft Press (exam 70-536) and there is some
Review questions after each chaper.
Here is the question "Which command would you use to close the application
domain in the following code sample."

AppDomain d = AppDomain.CreateDomain("New Domain");
d.ExecuteAssemblyByName("MyAssembly");

A. d. DomainUnload()
B. d = null
C. d.Unload()
D. AppDomain.Unload(d)

The right answer according to the book is B and D.
I have guessed only at D because I can't find why B is also included in
the right answer.
Because of the nature of the question I also got the impression that only
one answer is correct.

//Tony

Hi Tony

I'm not sure you got that one right.

i'm also reading that book at the moment, and the question you refer to
seems to be Chapter 8, Lesson 1, Question 3... And my answer sheet does not,
like you state, refer to answer B & D being the correct answers. That
answers refer in my book to question 1, where B & D are the correct answers.

For question 3, it correctly states answer D to be the correct one...

Quote:

3. Correct Answer: D
A. Incorrect: AppDomain.DomainUnload is an event that is called when an
application domain is unloaded.

B. Incorrect: Setting an application domain to null does not cause it to be
unloaded.

C. Incorrect: Instances of the AppDomain class do not contain an Unload
method.

D. Correct: To unload an AppDomain object, pass it to the static AppDomain.
Unload method.

UnQuote...

Are you sure you have read your book correctly??

/Finn
 
I'm reading a book from Microsoft Press (exam 70-536) and there is some
Review questions after each chaper.
Here is the question "Which command would you use to close the application
domain in the following code sample."

AppDomain d = AppDomain.CreateDomain("New Domain");
d.ExecuteAssemblyByName("MyAssembly");

A. d. DomainUnload()
B. d = null
C. d.Unload()
D. AppDomain.Unload(d)

The right answer according to the book is B and D.
I have guessed only at D because I can't find why B is also included in the
right answer.
Because of the nature of the question I also got the impression that only
one answer is correct.

B would make some objects available for garbage collected. But I can not
see anything in the docs that indicates that it would get the app domain
properly closed.

Arne
 
Tony Johansson said:
I see what you mean but assume that I create a person object from the
Person class like this
Person myPerson = new Person(add some data here to the c-tor);

I never used to set null to the object like this
myPerson=null;
So If I don't do this will this object myPerson never be garbage collected
because you will still have a reference.

So do you mean that when I'm finish with an object assign null to the
object

//Tony
As I see the issue was resolved in another response, this is of little value
to the thread.
However, my reference was from C++, which has no automatic garbage
collection. Thus, the object is destroyed using delete, leaving the pointer
(potentially) to cause issues. In your C# example, the rules of scope also
apply, so once the block of code where your object and object variable were
created finishes executing, both are gone.
 
Back
Top