none
keep a delegate passed to unmanaged code alive C# RRS feed

  • Question

  • I have this exception :

     

    “A callback was made on a garbage collected delegate of type WaveLib.WaveNative+WaveDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.”

    Any body can help me

    : (

    Thank You....

    Monday, June 21, 2010 9:42 PM

Answers

  • Store a reference to the delegate in your managed code.  As long as you keep a reference to the delegate, it will not get garbage collected.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    Monday, June 21, 2010 10:04 PM
    Moderator
  • Store a reference to the delegate in your native code.  As long as you keep a reference to the delegate, it will not get garbage collected.
    And by 'native' Reed meant 'managed', which is exactly what the error message says.
    • Marked as answer by SamAgain Tuesday, June 29, 2010 9:42 AM
    Monday, June 21, 2010 10:13 PM

All replies

  • Store a reference to the delegate in your managed code.  As long as you keep a reference to the delegate, it will not get garbage collected.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    Monday, June 21, 2010 10:04 PM
    Moderator
  • Store a reference to the delegate in your native code.  As long as you keep a reference to the delegate, it will not get garbage collected.
    And by 'native' Reed meant 'managed', which is exactly what the error message says.
    • Marked as answer by SamAgain Tuesday, June 29, 2010 9:42 AM
    Monday, June 21, 2010 10:13 PM