|
You don't need to do anything.
C# is a garbage collected language, which means when you have finished using an object, it will automatically be marked for garbage collection and removed from memory on the next pass.
You don't need to set it to null or anything, it will automatically be recognised as not in use once it passes out of scope.
(If you allocate _unmanaged_ resources in your class, like file handles, or database connections, then you should implement the dispose[^] pattern in the class to ensure they get cleaned up promptly)
Simon
|
|
|
|
|
Technically, you're working on "objects", not "classes". Terminology is important.
I believe that when the object goes out of scope, the garbage collector will eventually pick it up and free the memory.
Many of the .Net framework objects have a Dispose() method, so when you're done, you can call that. If you want to dispose your own objects, you have to derive from IDisposable , and override a few methods.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What you mean is that you create instances of the classes, i.e. object with that class as type.
Unless you are using unmanaged resources in your objects, you don't have to do anything at all. When the object isn't used any more, it will eventually get removed by the garbage collector.
You can set the reference to null if it's a variable that you are keeping, i.e. a member variable in an object that you will keep using (for example a member variable in a Form).
If it's a local variable that will go out of scope, you don't need to remove the reference. Setting the variable to null in that case will not affect the memory management at all.
Creating objects that is used for a very short time is very common in .NET. Take for example a statement like this (items and pages are integers):
string x = "There were " + items + " items in " + pages + " pages.";
This will create five short lived objects (two boxed integers, one object array and two strings containing the string representations of the integers) which will be up for garbage collection once the string is created.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi there! as you guys can see, the topic says my problem. This is what I did: I finish my application, and I published to localhost folder to test the updates function. After that I went back to the solution, I builded, it went OK, and after that it gives me the error what you can see from the topic of this issue? Anyone can help me with this problem? It's very urgent!!! Thx ahead
|
|
|
|
|
Hi,
Can anyone please tell me how to convert following script into C# code.
strComputer = "atl-ws-01"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
For Each objUser In objGroup.Members
If objUser.Name <> "Administrator" AND objUser.Name <> "Domain Admins" Then
objGroup.Remove(objUser.AdsPath)
End If
Next
Thanks,
Mushq
|
|
|
|
|
string strComputer = "atl-ws-01";
objGroup = GetObject(@"WinNT://" + strComputer + @"/Administrators");
foreach( objUser In objGroup.Members)
{
if( (objUser.Name != "Administrator") && (objUser.Name != "Domain Admins"))
objGroup.Remove(objUser.AdsPath);
}
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Ahsan, thank you very much for the reply, can you please tell me what should be the data type of variable objGroup and how to use objGroup in foreach loop.
Thanks a lot,
Mushq
Regards,
Mushq
|
|
|
|
|
Good Day,
What is the best way to transfer files from C# to a Mobile phone? I need to transfer a small XML file.
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
There are two ways of doing this, and I've done both in applications before.
The easiest way is to use ActiveSync (XP and earlier) or Windows Mobile Device Centre (WMDC) for copy the file you with a folder that is synced with the device. The benefit of this method is you simply write to a regular file on the desktop system, and it doesn't matter if the mobile device is connected or not. Worst case, the file is synced across next time the device connects.
The second way, which involves a little more work is to use RAPI.DLL (you still need ActiveSync or WMDC) installed to do this. The API in RAPI.DLL allows you to connect to a device through C# and copy information to and from the device. Your best bet here would be to look at the RAPI docs on MSDN, or look at a framework from OpenNETCF Consulting which from memory, is free.
------------------------
Luke Lovegrove
------------------------
|
|
|
|
|
Thanks for the reply, Luke.
Sorry for not making things clear enough.
What I would like to accomplish is not a PC <-> Mobile transfer, but a Server-Client architecture.
SERVER <--> [WIRELESS ROUTER] <--> MOBILE CLIENTS
So the Clients (MOBILE) will request for the XML file from the server, the server in turn will respond by sending the XML file from the requesting client.
Please advice. I'm thinking of using web service for this and thought that others here may have a better solution.
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
modified on Thursday, August 7, 2008 9:11 AM
|
|
|
|
|
Yeah, I'd probably suggest a web service of sorts for that. Keeping it as simple as possible is always the best thing to do, especially with mobile devices.
You could hit the server directly rather than through a web service if you were so inclined as well. I haven't used the Syetem.Net namespace much on desktops or mobile devices, but I suspect it would be a bit easier code wise to request it through a web service.
------------------------
Luke Lovegrove
------------------------
|
|
|
|
|
Hi All,
Can you please give me the equivalent code in C# for the following?
unsigned char CardType[2];
stu = MF_Request(DeviceAddr, 0, CardType);
Message("Request Card", stu);
String str;
char code[100];
if (stu == 0)
{
str = " ==> CardType(Hex): ";
sprintf(code,"%02X%02X",CardType[0],CardType[1]);
str += code;
}
Thanks in Advance
shahtech
|
|
|
|
|
What's the problem? If you have an equivalent for the MF_Request function (which I have no idea what it is), the translation is trivial.
|
|
|
|
|
Thanks for quick response,
Its not a predefined function, just I want to know the equivalent syntax thats it.
Thanks
|
|
|
|
|
byte[] CardType = new byte[2];
stu = MF_Request(DeviceAddr, 0, CardType);
Message("Request Card", stu);
string str = null;
if (stu == 0) {
str = string.Format(" ==> CardType(Hex): {0:x2}{1:x2}", CardType[0], CardType[1]);
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
(via C++ to C# Converter):
byte[] CardType = new byte[2];
stu = MF_Request(DeviceAddr, 0, CardType);
Message("Request Card", stu);
string str;
string code = new string(new char[100]);
if (stu == 0)
{
str = " ==> CardType(Hex): ";
code = string.Format("{0:X2}{1:X2}", CardType[0], CardType[1]);
str += code;
}
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++/CLI
|
|
|
|
|
I got a lib file from http://69.10.233.10/KB/IP/pop3client.aspx[^], and i was hoping someone could hep me with a problem im having.
I normally use thunderbird, so all the tests i do, i compare with the results from thunderbird. When i try to retrieve a plain text mail with the code i downloaded (above), it works great. The problem occurs when i try to download a compressed file (GZip compression algorythm).
This works fine with thunderbird, but the code i downloaded seems to hack up the file. When i compared the results with a hex editor (EditpadPro), the difference in files is enormous, your src seems to change the chars around (eg first 7 hex from thunderbird: 02 00 00 00 FF FF 73, first 7 from your src: 41 67 41 41 41 50 2F), also when i download the file with thunderbird is's 98 bytes, and when i use code i downloaded, the file size is 138 bytes.
This tells me that the file is still ok on the SMTP server, it's just when it gets downloaded. So im assuming its a encoding problem (not 100% sure).
Iv tried this with .Net 2.0, and Mono 1.9.1.
Thanks in advance.
George.
|
|
|
|
|
GeorgeBerry wrote: The problem occurs when i try to download a compressed file (GZip compression algorythm).
So, did you decompress the file after you downloaded it?
|
|
|
|
|
When i try to decompress the files, it doesnt work, i get an exception coz the file isnt in its origional state.
|
|
|
|
|
GeorgeBerry wrote: i get an exception coz the file isnt in its origional state.
Can you paste the exception?
Have you tried downloading the file manually and added a .gz extension, and checked inside the compressed file with WinZip/WinRAR?
|
|
|
|
|
The compression algorythm i use doesnt play well with gzip, and other progs, it doesnt have all the wrapper classes, and checks that they use, so only a bare GZip decompression stream will be able to decompress it.
The thing is, that i need to be able to download it with the lib file (mentioned above).
Also if i download the entire email with thunderbird, the chars are exactly the same as the with the lib file, its only when i tell thunderbird to download that attachment, that it works properly. Dont know if this behaviour provides necessary info or not.
Thanks.
|
|
|
|
|
GeorgeBerry wrote: The compression algorythm i use doesnt play well with gzip
Which one are you using? Why not use the builtin stuff in .NET?
GeorgeBerry wrote: Also if i download the entire email with thunderbird, the chars are exactly the same as the with the lib file, its only when i tell thunderbird to download that attachment, that it works properly. Dont know if this behaviour provides necessary info or not.
You sure the attachment is not in BASE64 instead of being compressed? This would make sense in light of your observations.
|
|
|
|
|
I am using the System.IO.Compression class, but if you use this, you cant just pull the compressed data out from any ol' compression app.
well, as far as iv been told, base64, is the textual interpretation of a binary file, so in this case, it would seem that it is base64. However when i try to
byte[] TempArr = System.Convert.FromBase64String(DownloadedText);
I get the exception message "Invalid character found.".
Just a side not, i dont know that much about encodings, just a little. This is the first time iv had to create a POP3 client.
|
|
|
|
|
GeorgeBerry wrote: well, as far as iv been told, base64, is the textual interpretation of a binary file, so in this case, it would seem that it is base64. However when i try to
byte[] TempArr = System.Convert.FromBase64String(DownloadedText);
I get the exception message "Invalid character found.".
You are probably passing too much data (it expects only the attachment bit, the garbled text), but I think you are on the right path with Base64
|
|
|
|
|
When i try to convert:
This is a multi-part message in MIME format.
--------------060102020601080008090504
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
--------------060102020601080008090504
Content-Type: application/octet-stream;
name="sig.zpf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="sig.zpf"
AgAAAP//c0/NL0pPVXBKLSqq5ApJzUktKUpMTi1S0AgoqdRU8ClJ4XLNTczMUUgHq3MogavQ
S87Xq0oEabFS0DAwMtRUMDEy0TW3tDDgck7NAQoaWBjrmhqb6RqbGJhzAQA=
--------------060102020601080008090504--
i get the error "Invalid character found.", when i try to convert:
--------------060102020601080008090504
Content-Type: application/octet-stream;
name="sig.zpf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="sig.zpf"
AgAAAP//c0/NL0pPVXBKLSqq5ApJzUktKUpMTi1S0AgoqdRU8ClJ4XLNTczMUUgHq3MogavQ
S87Xq0oEabFS0DAwMtRUMDEy0TW3tDDgck7NAQoaWBjrmhqb6RqbGJhzAQA=
--------------060102020601080008090504--
i get "Invalid length.", and when i try to convert:
AgAAAP//c0/NL0pPVXBKLSqq5ApJzUktKUpMTi1S0AgoqdRU8ClJ4XLNTczMUUgHq3MogavQ
S87Xq0oEabFS0DAwMtRUMDEy0TW3tDDgck7NAQoaWBjrmhqb6RqbGJhzAQA=
i get the error "Invalid character found.".
Yeeh, iv tried all 3... i know "reaching for straws" right.
lol, i just cant think of anything else too try.
Thanks for the replies, definately getting closer too the solution.
|
|
|
|
|