From: Tony Johansson on
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


From: PvdG42 on

"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:uCjrzRT6KHA.5016(a)TK2MSFTNGP02.phx.gbl...
> 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.


From: Tony Johansson on
"PvdG42" <pvdg42(a)toadstool.edu> skrev i meddelandet
news:u7qpU1T6KHA.1932(a)TK2MSFTNGP05.phx.gbl...
>
> "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
> news:uCjrzRT6KHA.5016(a)TK2MSFTNGP02.phx.gbl...
>> 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.
>

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


From: Finn Stampe Mikkelsen on
"Tony Johansson" <johansson.andersson(a)telia.com> skrev i meddelelsen
news:uCjrzRT6KHA.5016(a)TK2MSFTNGP02.phx.gbl...
> 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
>
>
From: Arne Vajhøj on
On 01-05-2010 09:44, Tony Johansson wrote:
> 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