JPEGVideoSource increases memory use in SearchResultUserControl

Hello,

I am using JPEGVideoSource to add a snapshot to customize the SearchResultUserControl class in a plugin integration, but I am facing an increasing SmartClient memory use after each time the search runs. The call to JPEGVideoSource.Close() doesn’t seem to fix the issue.

Please let me know if I am doing something wrong.

Below the code :

public partial class MyResultControl : SearchResultUserControl

{

public MyResultControl()

{

  InitializeComponent();

  DataContext = this;

}

public ImageSource Image { get; set; }

public string EventName { get; set; }

public string DHM { get; set; }

public override void Init(SearchResultData searchResultData)

{

  var result = (MySearchResultData)searchResultData;

  EventName = result.EventName;

  DHM = result.TriggerTime.ToLocalTime().ToString();

  Image = CameraScreenShot(result.Item, result.TriggerTime);

  OnPropertyChanged(nameof(EventName));

  OnPropertyChanged(nameof(DHM));

  OnPropertyChanged(nameof(Image));

}

private BitmapSource CameraScreenShot(VideoOS.Platform.Item cam, DateTime dhm)

{

  BitmapSource bmps = null;

  if (cam.FQID.Kind == VideoOS.Platform.Kind.Camera)

  {

      JPEGVideoSource \_imageVideoSource = new JPEGVideoSource(cam);

      \_imageVideoSource.Init();

      var imgData = \_imageVideoSource.GetAtOrBefore(dhm.ToUniversalTime()) as JPEGData;

      if (imgData != null)

      {

        bmps = imgData.ConvertToBitmapSource();

      }

      \_imageVideoSource.Close();

  }

  return bmps;

}

}

We have tested your code with a plugin reusing some of your code but we have not been able to reproduce the issue that you mentioned. For further investigation, can you please explain how to reproduce the symptom? (Details we might be missing?) Also please verify that you are using the newest SDK (2020 R3 currently).

Thank you for your replay,

Below is how the search is done before calling MyResultControl:

private void SearchInternal(Guid sessionId, DateTime from, DateTime to, IEnumerable items,bool ascendingSortOrder, CancellationToken cancellationToken)

{

/* Event Filter “myFilter” definition

*/

    EventLine\[\] events;

    int startIndex = 0;

    int found = 0;

int _resultChunkLength = 999;

    while (startIndex == 0 || found > \_resultChunkLength)

    {

      events = alarmClient.GetEventLines(startIndex, \_resultChunkLength + 1, myFilter);

      FireSearchResultsReadyEvent(sessionId, GetResult(events, items));

      found = events.Length;

      startIndex += \_resultChunkLength + 1;

    }

  }

private List<MySearchResultData> GetResult(EventLine\[\] events, IEnumerable<Item> items)

{

  List<MySearchResultData> results = new List<MySearchResultData>();

  foreach (EventLine line in events)

  {

var triggeredAt = line.Timestamp;

Item cam = items.Where(x => line.SourceId == x.FQID.ObjectId).FirstOrDefault();

var id = GuidUtil.Create(XpSCAdmSearchSearchAgentPlugin.PluginId,

line.SourceId.ToString(),

line.Type,

triggeredAt.Ticks.ToString(CultureInfo.InvariantCulture));

MySearchResultData result = new MySearchResultData(id)

{

Item = cam,

BeginTime = triggeredAt.AddSeconds(-30),

TriggerTime = triggeredAt,

EndTime = triggeredAt.AddSeconds(30),

EventName = line.Type

};

results.Add(result);

  }

  return results;

}

It seems pretty clear that you have a memory leak somewhere, but to figure out exactly where is a little harder. Our recommendation would be going through the code and removing parts until the problem stops showing up. We haven’t been able to reproduce the issue in our code.