|
|
Smart I like. Smart ass I can do without.
I ALWAYS Google first. I don't want some obsucre explanation or 3rd party products. I'm looking for someone I can ask questions to. A CP'er would pe preferable, hence my post.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Is Skype a "3rd party"? You got a lot of choices; including (native) UWP VOIP classes. And "code projects".
Simple SIP (VOIP) based phone in C#
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: Is Skype a "3rd party"?
Anything you (or someone on the team) didn't personally write is considered to be "3rd party", even if you have the source code.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm a bit more general: Anything in the MS stack made by MS I consider "first party" when I'm working with MS (and the user doesn't have to pay / license extra for).
Now with UWP, it's native; unless you go Xamarin, then it's 3rd party: IOS and Android; BUT only if you deploy to them.
So, yes, I would use the Skype API if it worked for me and would consider it "first party". (Or second ... who's on second?)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 12-Apr-19 15:24pm.
|
|
|
|
|
|
Your requirements are not specific enough.
If this is just something you are messing with then yes an existing API (like skype) makes the connectivity 'easier' to some extent. But only some because you must figure out the specifics of the api.
Other wise you roll your own.
1. Figure out how to build a client server app
2. Figure out to capture audio
3. Figure out how to play audio
4. Create a 'protocol' that allows your client/server to pass audio.
5. Build a rudimentary UI so one can see the clients.
6. Put all of the above together to produce what you want.
|
|
|
|
|
1) in one of my routine i used many list and dataset. i populated those with high volume of data. when event used end then clear memory for list like
list1 = null and GC.Collect() in my routine but i am not sure that memory occupied by List1 is instantly clear or will be clear later. please share the knowledge.
2) in case of dataset i clear like
dataset1.Dispose()
dataset1=null
GC.Collect()
but i am not sure that memory occupied by dataset1 is instantly clear or will be clear later. please share the knowledge.
3) if i call GC.Collect() several time in my one routine does degrade the performance of my application ?
i found one link which said best option to release memory for list this way
first clear List and then call TrimExcess. is it the right one ?
i used like
list1=null & GC.Collect()
which one is best to clear memory for list instantly ?
please see my code below which works well.
private void button2_Click(object sender, EventArgs e)
{
var before = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
List<string> lst1 = new List<string>();
for (int i = 0; i <= 1000000; i++)
{
lst1.Add("Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test ");
}
var after = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
lst1.Clear();
lst1.TrimExcess();
var current = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
}
please share best option to clear memory for list & dataset instantly. thanks
|
|
|
|
|
Hi,
1.
one seldom needs to worry about memory management when using C# or other .NET programming languages. Do you have positive proof there is a memory problem? Does your app use gigabytes of data (assuming a PC with several GB of physical memory)?
2.
A List<T> basically is an array containing references (pointers) to objects of type T. The memory taken by the list itself therefore is only 8 bytes multiplied by its capacity, which automatically is a power of two, and larger than the maximum number of items your list ever held, unless you explicitly reduce its size by calling TrimExcess() or setting Capacity .
3. Normally the objects themselves take much more memory than the list that holds references to them.
4.
If you think you need to worry about the memory taken by the list, make sure your listed items are referenced only by said list; if not, these objects will stay alive and hence occupy memory.
5.
Calling GC.Collect() is to be avoided, it can severely reduce performance as it scans your entire object world trying to locate dying objects. And there seldom is a need, GC collection will happen automatically when .NET feels a need to free some memory.
6.
The one thing you should do (and probably already are doing) is disposing of objects that offer a Dispose() method.
|
|
|
|
|
i have used several list where storing data from large xml files. now clearing my list this way.
calling GC.Collect() at end of operation. please tell me is this approach is good or not ?
List1.clear();
List1.TrimExcess()
List1=null ;
List2.clear();
List2.TrimExcess()
List2=null ;
List3.clear();
List3.TrimExcess()
List3=null ;
GC.Collect();
|
|
|
|
|
Most likely not necessary, inefficient, redundant, and not good as explained before.
|
|
|
|
|
|
true... at that point he should use unsafe code. possibly.
|
|
|
|
|
In practice, TrimExcess does nothing to "free memory" - look at the Reference Sources if you aren't sure: Reference Source[^]
You will find that in effect all it does is set the internal array to an empty array, it doesn't do anything "fancy" with the memory it no longer wants. Indeed, if you use TrimExcess to set a smaller size to the internal array, it will use more memory to do that, not less!
Don't mess with the GC - leave it alone and let it come in when it needs to. The best way to free memory is to set all references to the object to null and let the memory management handle it in it's own time. It's probably a lot better than you are at doing this!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This explanation is not clear....please elaborate it if possible with example.
Indeed, if you use TrimExcess to set a smaller size to the internal array, it will use more memory to do that, not less!
|
|
|
|
|
Look at the reference source that I linked to - it's the actual source code for the List<T> class.
Now look at what happens when you set a size half as big as it is at the moment, and follow that into the Capacity property setter. What does the code do when you halve the capacity?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Calling GC.Collect() may not immediately release the memory. If you want to make sure it does that, you can do do this:
GC.Collect();
GC.WaitForPendingFinalizers();
Keep in mind that the WaitForPendingFinalizers method blocks the calling thread until it returns.
Like everyone else has said, you should probably leave the garbage collector alone, and be more vigilant about references to the object(s) in question. As long as another object holds a reference to another object, that referenced object remains in memory.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
what GC.WaitForPendingFinalizers(); does ? does it call garbage collector immediately or something else ?
|
|
|
|
|
GC.WaitForPendingFinalizers Method (System) | Microsoft Docs[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
It is important to understand the difference between memory that is being used and memory that at one time was used. The first cannot be freed by any means. You must stop using it and when you do then it moves into the second category where it might be freed.
If your allocations are below 85,000 bytes then any allocation request will do a garbage collection itself if there is not enough free memory to meet the needs of the request. This will happen (basically) up until you run out of memory because you are 'using' all of it. It will not free memory if you are using(pointing) to it.
If the allocated size is larger than 85,000 bytes (bytes, not chars, ints, etc) then the memory handling is slightly different in that between allocating and free allocations, if those are not somewhat sequential one can end up with having enough free memory but not actually succeeding in getting it because the memory is fragmented. For more on that you must learn quite a bit about how "heaps" in general work (not just C#) and how those can become fragmented. Once you understand that then you can look at the C# "Large Object Heap".
Your loop has 1,000,000 items and for a 64 bit machine you would need to have an item in every member of that list and each item would need to be about 10,000 bytes in size before I would suspect it to be a problem.
Mou_kol wrote: button2_Click
Regardless of the above however that method suggests a UI. And a UI list with a million items in it is a BAD design.
Any UI with a list that attempts to contain more than 1000 items EVER, is a BAD design. And that might even be high.
Learn how to do paging instead. Also learn how to provide a method that allows the user to provide criteria and search for what they want in the list.
|
|
|
|
|
What nobody has asked or said anything about is "What are you using to determine if memory is being freed?"
If you're looking in Task Manager to see how much memory your app is using, DO NOT DO THAT! Task Manager is lying to you. It's showing you how much memory is RESERVED for your app, not how much it's actually using.
When you start a .NET app, the .NET Common Language Runtime (CLR) gets a block of memory from Windows and makes that block the "managed heap". The code for you app is loaded and every object your app creates is allocated using memory from the managed heap. When your app is freeing objects up, the memory is returned to the managed heap, NOT to Windows. If the CLR needs more memory for your app, its asks Windows for another block of memory. If Windows needs more memory, it can ask the CLR to return any free memory its can spare, which the CLR will happily return.
Task Manager is showing you the memory the CLR is holding onto, not how much your app is actually using. If you want to see how much your app is using, you have to use PerfMon and the .NET Memory counters.
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
{
var before = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
List<string> lst1 = new List<string>();
for (int i = 0; i <= 1000000; i++)
{
lst1.Add("Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test ");
}
var after = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
lst1.Clear();
lst1.TrimExcess();
var current = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
}
i saw TrimExcess() clear memory for list instantly and it is bit better than list = null & GC.Collect....am i right?
one request that please tell me what List TrimExcess() does and when to use it ?
please come with a example which explain the objective of List TrimExcess() .
i want to understand the actual usage of TrimExcess() function.
thanks
|
|
|
|
|
|
I have a form with a lot of controls on it like Buttons, TextBoxes, Panels and so on, and I've defined some properties such as Button_BackColor, Panel_Width, Label_ForColor, App_Font in the Settings.settings file. All things work at runtime but I want to apply this settings as design time, so that I could feel it without running. What can i do?
|
|
|
|
|
As I understood those new Properties are belonging to the Form / are declared on the Form - I call it myForm.
If you want to see them at DesignTime you must use this Form as a template - that means you must derive your new Form from this (allready defined) myForm.
|
|
|
|