473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

removing string reference question

string SelectedSite
using (SiteLauncher SiteLaunch = new SiteLauncher()
{
SiteLaunch.ShowDialog();
SelectedSite = SiteLaunch.SelectedPokerRoom; //this is
a property that returns a string
}

My question is, if after the using block is over, will the SiteLaunch
object be able to dispose itself? Or does it stay alive because of the
open reference with SelectedSite. If this is the case, is there a
better way of doing this?

Thanks

Jul 26 '07 #1
3 1304
Goose14 <gu*******@gmail.comwrote:
string SelectedSite
using (SiteLauncher SiteLaunch = new SiteLauncher()
{
SiteLaunch.ShowDialog();
SelectedSite = SiteLaunch.SelectedPokerRoom; //this is
a property that returns a string
}

My question is, if after the using block is over, will the SiteLaunch
object be able to dispose itself? Or does it stay alive because of the
open reference with SelectedSite. If this is the case, is there a
better way of doing this?
No, it's fine. SiteLaunch may refer to the string, but the string won't
refer to the SiteLaunch.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 26 '07 #2
On Thu, 26 Jul 2007 12:49:05 -0700, Goose14 <gu*******@gmail.comwrote:
string SelectedSite
using (SiteLauncher SiteLaunch = new SiteLauncher()
{
SiteLaunch.ShowDialog();
SelectedSite = SiteLaunch.SelectedPokerRoom; //this is
a property that returns a string
}

My question is, if after the using block is over, will the SiteLaunch
object be able to dispose itself? Or does it stay alive because of the
open reference with SelectedSite. If this is the case, is there a
better way of doing this?
SelectedSite doesn't refer to the SiteLauncher instance. It refers to the
string that the SiteLauncher instance returned. So I don't see any reason
that SelectedSite would in any way affect the lifetime of SiteLaunch, or
in any way be affected by the disposal of SiteLaunch.

That said, suppose you have actually referenced the SiteLauncher instance
somehow and retained that reference outside the "using" statement block.
For example, instead of referencing something simple like a string that is
immutable and doesn't contain a reference back to anything else, perhaps
you had a reference to something that was modified by SiteLauncher during
disposal, or which kept a reference to the SiteLauncher object.

Then you would in fact have a problem. My understanding is that not only
"will the SiteLaunch object be able to dispose itself", that's exactly
what the "using" statement always does. It always disposes the object,
before exiting the "using" statement. So if the retained object was
modified by disposal of the SiteLauncher instance, or you were somehow
able to get the SiteLauncher instance reference from the retained object,
that would be an issue. The simple answer is to not do that. :)

Pete
Jul 26 '07 #3
On Jul 26, 2:49 pm, Goose14 <gusabd...@gmail.comwrote:
string SelectedSite
using (SiteLauncher SiteLaunch = new SiteLauncher()
{
SiteLaunch.ShowDialog();
SelectedSite = SiteLaunch.SelectedPokerRoom; //this is
a property that returns a string
}

My question is, if after the using block is over, will the SiteLaunch
object be able to dispose itself? Or does it stay alive because of the
open reference with SelectedSite. If this is the case, is there a
better way of doing this?

Thanks
Thank you to both.

Jul 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve | last post by:
Hi, I have a table which contains records of user access and searches made within an application, this is a sample of the data: response for 101 results from database in 28906 ms I only...
3
by: Guadala Harry | last post by:
In the following line of code, what is the point of including the 'new' keyword? List.Changed -= new ChangedEventHandler(ListChanged); I'm just a bit confused because I thought 'new' was used...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
6
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
3
by: MLH | last post by:
Back in mid-2003, lucason posted a question about removing punctuation chars from a string. Suggested code was posted using Replace function. Could the FN below be easily modified for use with A97...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.