0

How it must work:

WindowsMediaPlayer windowsMediaPlayer = new WindowsMediaPlayer(); 
IWMPMediaCollection collection = windowsMediaPlayer.mediaCollection;
IWMPMedia newMedia = collection.add(path);  //causes OutOfMemoryException after some thousands  method's iterations

I've tried to avoid it this way:

try
{
    newMedia = collection.add(path);
    return newMedia;
}
catch (Exception)
{
    collection = null;
    GC.Collect();
    GC.WaitForPendingFinalizers();
    WindowsMediaPlayer windowsMediaPlayer = new WindowsMediaPlayer();
    IWMPMediaCollection collectionNew = windowsMediaPlayer.mediaCollection;
    return CreateNewMedia(collectionNew, path);
}

But this does not work – I still get infinite exception loop inside catch.

1 Answers1

0

You can not handle OutOfMemoryException like ordinary one. The reason you may have handling that, is just, in some way, to save the state of application, in order to provide to the consumer of your application a way to recover lost data. What I mean is that there is no meaning calling GC.Collect or whatever, cause application is going to dead anyway, but CLR kindly give you notification about that before.

So to resolve this issue, check the memory consumption of your application, that on 32bit machine has to be something about 1.2GB of RAM, or control the quantity of the elements in collections you have, that can not exceed, for ordinary list, 2GB of memory on 32bit and on 64bit too.

Tigran
  • 61,654
  • 8
  • 86
  • 123