2

I'm having an issue with LinqToTwitter 4.1 where having a user stream open will eventually cause the programs memory usage to balloon out of control. This does not occur when the program starts running but only after some time, normally after a day or two.

Using the ANTS Memory Profiler I find this reference chain preventing System.Byte[] from being collected. The full profiler results can be downloaded here. enter image description here

Code:

  private async Task<Streaming> TwitterSteam(string trackHashTags, string twitterUserIds)
    {
        var stream = (from strm in TwitterCtx.Streaming.WithCancellation(CloseStreamSource.Token)
                      where strm.Type == StreamingType.Filter &&
                      strm.Track == trackHashTags
                      && strm.Follow == (string.IsNullOrEmpty(twitterUserIds) ? "41553192" : twitterUserIds)
                      select strm).StartAsync(async strm =>
                     {

                         string message = string.IsNullOrEmpty(strm.Content) ? "Keep-Alive" : strm.Content;
                         if (message == "Keep-Alive")
                         {
                             IsRunning = true;
                         }
                         else
                         {
                             JsonData data = JsonMapper.ToObject(message);
                             Status tweet = new Status(data);
                             LogClient.LogInfo("Received Tweet: " + tweet.Text, null, LogType.Info, null);
                             ConvertToMessage(tweet);
                             IsRunning = true;
                         }
                     }).Result.SingleOrDefault();

        return stream;
    }

Can anyone provide insight as to why this is occurring and how I can prevent it?

Richard Mosley
  • 111
  • 1
  • 6

0 Answers0