Click here to Skip to main content
15,896,348 members
Home / Discussions / C#
   

C#

 
GeneralRe: OPC client server Pin
Dave Kreskowiak5-Oct-18 2:16
mveDave Kreskowiak5-Oct-18 2:16 
GeneralRe: OPC client server Pin
Roberto64_Ge8-Oct-18 2:16
Roberto64_Ge8-Oct-18 2:16 
GeneralRe: OPC client server Pin
Dave Kreskowiak8-Oct-18 4:10
mveDave Kreskowiak8-Oct-18 4:10 
GeneralRe: OPC client server Pin
Roberto64_Ge8-Oct-18 4:45
Roberto64_Ge8-Oct-18 4:45 
GeneralRe: OPC client server Pin
Dave Kreskowiak8-Oct-18 8:21
mveDave Kreskowiak8-Oct-18 8:21 
QuestionActive touchscreen detection Pin
sarmadi2-Oct-18 19:43
sarmadi2-Oct-18 19:43 
QuestionHow should JSON Deserializer work ? (basic question). FIXED. Pin
Maximilien2-Oct-18 9:04
Maximilien2-Oct-18 9:04 
QuestionAsync Memory leak ... Pin
Super Lloyd1-Oct-18 21:13
Super Lloyd1-Oct-18 21:13 
It seems I have a memory leak in my app. Which I seem to be able to reproduce with this simple console app.
Could anyone tell me what I am missing or where I am mislead?
(FYI, working set is printed about every seconds..)
C#
using System;
using System.Threading;
using System.Threading.Tasks;

namespace CrazyAsync
{
    class Foo
    {
        public Func<CancellationToken, Task> Work;

        public async Task DoWork(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
                await Work?.Invoke(token);
        }
    }
    class Mamamia
    {
        public Task DoIt(CancellationToken token)
        {
            var t = Task.Delay(6, token);
            t.ContinueWith(x => 
            {
                if (x.Status == TaskStatus.Faulted)
                    Console.WriteLine(x.Exception.InnerException);

                if (i++ % 100 == 0)
                {
                    GC.Collect();
                    Program.DumpMemory();
                }
            });
            return t;
        }
        int i = 0;
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var cc = new CancellationTokenSource(TimeSpan.FromMinutes(1));
            var m = new Mamamia();
            var foo = new Foo()
            {
                Work = m.DoIt,
            };

            await foo.DoWork(cc.Token);
        }
        public static void DumpMemory()
        {
            var m = Environment.WorkingSet;
            Console.WriteLine($"Mem: {m:#,###}");
        }
    }
}

[EDIT] my bad, the memory only seems to increase for 2 minutes after all.... must be a wrong lead Cry | :((
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 2-Oct-18 4:28am.

AnswerRe: Async Memory leak ... Pin
Nathan Minier2-Oct-18 1:31
professionalNathan Minier2-Oct-18 1:31 
QuestionSqlite DB Verification Pin
Member 1394838230-Sep-18 20:24
Member 1394838230-Sep-18 20:24 
AnswerRe: Sqlite DB Verification Pin
Richard MacCutchan30-Sep-18 21:11
mveRichard MacCutchan30-Sep-18 21:11 
AnswerRe: Sqlite DB Verification Pin
OriginalGriff30-Sep-18 21:17
mveOriginalGriff30-Sep-18 21:17 
QuestionBeginning Student Array Question Pin
Member 1400299730-Sep-18 14:41
Member 1400299730-Sep-18 14:41 
AnswerRe: Beginning Student Array Question Pin
Dave Kreskowiak30-Sep-18 17:56
mveDave Kreskowiak30-Sep-18 17:56 
AnswerRe: Beginning Student Array Question Pin
OriginalGriff30-Sep-18 19:51
mveOriginalGriff30-Sep-18 19:51 
QuestionPython httpServ.request in C# - HttpWebRequest ? Pin
Member 1400288230-Sep-18 9:59
Member 1400288230-Sep-18 9:59 
AnswerRe: Python httpServ.request in C# - HttpWebRequest ? Pin
Richard MacCutchan30-Sep-18 21:08
mveRichard MacCutchan30-Sep-18 21:08 
GeneralRe: Python httpServ.request in C# - HttpWebRequest ? Pin
Member 140028821-Oct-18 11:26
Member 140028821-Oct-18 11:26 
QuestionSwitching 2 Variables Pin
Member 1400283730-Sep-18 8:19
Member 1400283730-Sep-18 8:19 
AnswerRe: Switching 2 Variables Pin
Dave Kreskowiak30-Sep-18 8:53
mveDave Kreskowiak30-Sep-18 8:53 
GeneralRe: Switching 2 Variables Pin
Member 1400283730-Sep-18 10:55
Member 1400283730-Sep-18 10:55 
AnswerRe: Switching 2 Variables Pin
BillWoodruff14-Oct-18 15:35
professionalBillWoodruff14-Oct-18 15:35 
QuestionFundamental misunderstanding of structs as "value" types Pin
bh_28-Sep-18 3:54
bh_28-Sep-18 3:54 
AnswerRe: Fundamental misunderstanding of structs as "value" types Pin
OriginalGriff28-Sep-18 4:12
mveOriginalGriff28-Sep-18 4:12 
GeneralRe: Fundamental misunderstanding of structs as "value" types Pin
bh_28-Sep-18 4:49
bh_28-Sep-18 4:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.