|
Hi leppie,
When i = null is assigned, there are no reference pointers pointing to the singleton object. Hence if there is a GC, then the singleton object has to be deleted. In this case, next time an instance to the singleton object is created, it should be a new object again. But the old object is being retained and returned when i call createInstance() again.
Basically, when will the singleton object be destroyed from memory?
We understand that an object will be deleted if there are no references to that object or if the object is set to null. Is this right?
Thanks and Regards
Madhu
|
|
|
|
|
When all object references are removed it is scheduled for garbage collection. The first round of the GC does the clean up. The next time the GC runs it removes it. If you need to free resources implement the IDisposable method and call that before assigning null and then just don't worry about it.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Event we tried to GC the i object after assigning to null ie.
i=null;
GC.Collect();
Thread.Sleep(2000);// Waitin for some time to Collect the object i by GC
even this never destroyed the object.
|
|
|
|
|
And if custom memory management is so important you shouldn't be using C#.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
madhusri wrote: When i = null is assigned, there are no reference pointers pointing to the singleton object.
This is incorrect. The class you showed has a static reference to its one and only instance.
madhusri wrote: But the old object is being retained and returned when i call createInstance() again.
And it manages this because something is holding a reference that the CreateInstance() method can pass back.
madhusri wrote: We understand that an object will be deleted if there are no references to that object or if the object is set to null. Is this right?
The first part is correct. The second part is incorrect because you are not setting the object to null, not now, not ever. What you are doing is setting a reference to the object to null.
|
|
|
|
|
Now we understand. Out situation is like One exe will invoke function in 2 separate dlls using reflection. first exe loaded the dlls. those dlls create log object using CreateInstance(). suppose if the dll1 assigned the
logobject.Moudulename="First";
logobject=null;<br />
GC.Collect();
then the exe unloaded this dll1 and try to access dll2 function which uses logobject instance, will the changes made by dll1 will be afected to dll2's Logobject? if yes means the logobjected is collected by GC right so it will be no longer available to dll2 rite?
|
|
|
|
|
I think you need to dispose the object out of memory.
Assigning null is no different then assigning a value. The object itself still exists.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
madhusri wrote: since we assigned i=null then the singleton must be destroyed and new instance should be created when j = single.CreateInstance(); executed right?
Nope, wrong!
See this code from CreateInstance:
if (s == null)
s = new single();
return s; What happens here is the one and only ever instance never to be repeated is created if it does not exist and stored in the static field called s. s is always returned. Nothing else ever assigns to s therefore the singleton pattern is maintained becuase you have ensured that there will only ever be one and only one ever instance of the object. This is the goal of the singleton, the behaviour you expect is at odds with the pattern you have chosen.
|
|
|
|
|
I want to set the font style to Bold when the user clicks Control + B key combination,
How do i do that?
Thanks & Regards,
Pramod
|
|
|
|
|
private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.B && e.Modifiers == Keys.Control)
{
this.richTextBox1.SelectionFont = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);
}
}
|
|
|
|
|
|
You could also maintain the font and do it like this:
if (e.KeyCode == Keys.B && e.Control)
{
richTextBox1.SelectionFont = new Font(
richTextBox1.SelectionFont,
richTextBox1.SelectionFont.Style ^ FontStyle.Bold
);
e.Handled = true;
}
Michael Francik
Empireland, Inc.
|
|
|
|
|
Everything is fine
but when i press Ctrl + I the cursor moves one tab ahead,
Why does this happen?
is Ctrl + I any pre-defined short cut for richtextbox.
i am working in VS 2005.
Thanks,
Pramod
|
|
|
|
|
Thanks for that can also tell me how can i insert a link to a Folder in a richtext box.
Pramod
|
|
|
|
|
See this:
http://msdn2.microsoft.com/en-us/library/f591a55w.aspx
|
|
|
|
|
i tried but when i set a link as http://microsoft.com the text display should be only microsoft.com , but the text displayed is http://microsoft.com
please suggest Any other way to solve this.
Thanks,
Pramod
|
|
|
|
|
For example, if you want to open Directory c:\ then use
file:\\c:\
or if you want to open d:\temp then use
file:\\d:\temp
|
|
|
|
|
Hi,
How do i control access to a directory or file in a network programatically .Im using .Net Framework 1.1
(I have to restrict access to network for a particular user programatically)
Thanks in advance,
Luck is Opportunity with hardwork
|
|
|
|
|
Anything you do programmatically is in the context of the user that is running your program. If you want to kill access for a user, you cannot change a directory access while 'being' that user.
The only way is with network security setting the access rights on the folder. That's why we have network administrators in the world.
|
|
|
|
|
Thanks for your comments..
But is it possible to watch a directory for any changes,like we have FileSystemWatcher for files.
(or)
Is it possible to raise an Event if a shared directory is being accessed in windows.
I am using .Net Framework 1.1
Thanks in advance..
Luck is Opportunity with hardwork
|
|
|
|
|
Hi,
I need to develop a .NET application in C# that will run in a client machine.
This application should connect to a sharepoint server running in another machine, authenticate using username and password, and copy specified files from the sharepoint portal server.
I tried to use Microsoft.Sharepoint dll in the client side code, but the following error was occurring "But when I run the Application it says that the COM component is not registered or unavailable" . i feel the dll should be used only in the sharepoint server machine only.
Could someone help me in how to go about doing this.. if possible, some code snippetts will be of great help.
Thanks
Nishanth
|
|
|
|
|
Hi
I want to print a batch of invoices using crystal report. Now I am doing this using selection formula so it will send report by report to the printer.
There is an option call Group selection formula but I don’t know how to use this, is it a another way to get it done???
Shone
|
|
|
|
|
We use follwing code to create .avi file
IBaseFilter mux;
IFileSinkFilter sink;
int hr = capGraph.SetOutputFileName(MediaSubType.Avi, fileName, out mux, out sink);
DsError.ThrowExceptionForHR(hr);
hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, theDeviceCapture, theCompressor, mux);
DsError.ThrowExceptionForHR(hr);
WE want to change fileName ,but, when we make this, the second part of code give following error
System.Runtime.InteropServices.COMException was unhandled
Message="One or more arguments are invalid"
Source="DirectShowLib"
ErrorCode=-2147024809
How can create .avi files which have different names from capture card in C#
Murat Coşkun
Design Engineer
VESTEK Elektronik Arastima Gelistirme A.S.
E-Mail : murat.coskun@vestel.com.tr
|
|
|
|
|
Hello all,
i want to show millseconds along with longtime.
how to do this
regards
GV Ramana
|
|
|
|
|
Is this what you want ?
DateTime now = DateTime.Now;
Console.WriteLine(now.Millisecond);
Console.WriteLine(now.Ticks);
|
|
|
|