Hi ,
For our application we need several UCMA (4.0.7577.203) player, which plays endless music (similar to a music on hold player). Recently we discovered, that the usage of memory raises constantly over the time. We investigated the problem with ANTS memory profiler and discovered not disposed timer objects.
We tried to reproduce the problem with a very simple application, which just starts a UCMA player and plays endless one single file. We found out, that each time the player ends, a System.Timers.Timer object with its references is left in the memory.
Unfortunately this little memory leak has a big impact on our application with over 100 "endless" players (avg. music length 2 seconds).
Is it possible to force the disposing of the timer objects?
Thanks
using System; using System.Configuration; using System.Threading; using Microsoft.Rtc.Collaboration; using Microsoft.Rtc.Collaboration.AudioVideo; namespace EndlessMusicPlayer { public class EndlessPlayer { private CollaborationPlatform _platform; private readonly object _token = new object(); private static bool _first; private Player _player; public void Startup() { var applicationUrn = ConfigurationManager.AppSettings["applicationUrn"]; var applicationUserAgent = ConfigurationManager.AppSettings["applicationUserAgent"]; var platformSettings = new ProvisionedApplicationPlatformSettings(applicationUserAgent, applicationUrn); var platform = new CollaborationPlatform(platformSettings) { InstantMessagingSettings = { SupportedFormats = InstantMessagingFormat.PlainText } }; platform.RegisterForApplicationEndpointSettings(OnWebConversationEndpointFound); platform.ProvisioningFailed += OnProvisioningFailed; //starts the CollaborationPlatform try { platform.BeginStartup(OnPlatformStartupComplete, platform); } catch (Exception ex) { Console.WriteLine("Couldn't start the collaboration platform: " + ex.Message); } } private void OnPlatformStartupComplete(IAsyncResult ar) { try { var platform = ar.AsyncState as CollaborationPlatform; if (platform != null) { platform.EndStartup(ar); _platform = platform; } } catch (Exception ex) { Console.WriteLine("Couldn't start the collaboration platform: " + ex.Message); } } private void OnWebConversationEndpointFound(object sender, ApplicationEndpointSettingsDiscoveredEventArgs args) { lock (_token) { if (!_first) { _first = true; var applicationSettings = args.ApplicationEndpointSettings; applicationSettings.UseRegistration = false; applicationSettings.IsDefaultRoutingEndpoint = true; var endpoint = new ApplicationEndpoint(_platform, applicationSettings); endpoint.BeginEstablish(OnEndpointEstablished, endpoint); } } } private void OnEndpointEstablished(IAsyncResult result) { var endpoint = result.AsyncState as ApplicationEndpoint; if (endpoint != null) { try { endpoint.EndEstablish(result); _player = new Player(); _player.SetMode(PlayerMode.Manual); var source = new WmaFileSource("test.wma"); source.EndPrepareSource(source.BeginPrepareSource(MediaSourceOpenMode.Buffered, null, null)); _player.SetSource(source); _player.StateChanged += PlayerStateChanged; _player.Start(); Console.WriteLine("Player started."); } catch (Exception ex) { Console.WriteLine("Couldn't start the endless player: " + ex.Message); } } } private static void PlayerStateChanged(object sender, PlayerStateChangedEventArgs e) { if (e.State == PlayerState.Stopped) { //player stopped, start again var player = sender as Player; if (player != null) { ThreadPool.QueueUserWorkItem(obj => { Console.WriteLine("Player started again."); player.Start(); }); } } } private static void OnProvisioningFailed(object sender, ProvisioningFailedEventArgs args) { Console.WriteLine("Provisioning failed: " + args.Exception); } } }