Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET COM+ WPF static VC++ , +
I have one Initialize() in my class and I am calling a delegate wrapper method from this function as follows (the call back method will call around 20 times in a sec),
 
public Initialize()
{
                CX_OUTPUT_CALLBACK cb = new CX_OUTPUT_CALLBACK(OutDelegateCb);
                AureusSDK_Wrapper_VideoCallbackFunSetup.CX_SetOuputCallBack(cb, cnt);
}
 
public static void OutDelegateCb(IntPtr p_aureus_video_output, int num_of_people, IntPtr pObject)
{
 //Process the video...
}
 
I am getting the below error, when I execute the method. Could you anyone help me to resolve this issue:
 
A callback was made on a garbage collected delegate of type 'FaceTracker_Abc!AAA.VideoAnalytics.Framework.Implementations.FaceTracker_Abc.CX_OUTPUT_CALLBACK::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.
Posted 27-Jun-13 1:28am
Edited 27-Jun-13 2:19am
_duDE_8.1K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

public Initialize()
{
                CX_OUTPUT_CALLBACK cb = new CX_OUTPUT_CALLBACK(OutDelegateCb);
                AureusSDK_Wrapper_VideoCallbackFunSetup.CX_SetOuputCallBack(cb, cnt);
                GC.KeepAlive(cb);
}
 
public static void OutDelegateCb(IntPtr p_aureus_video_output, int num_of_people, IntPtr pObject)
{
 //Process the video...
}
 
That would prevent garbage collection from collecting your object. The problem is that you don't havea ny reference (outside of COM) to the "cb" variable. Since garbage collecting is a reference counting operation, when the garbage collector runs it sees the "cb" is not referenced anywhere and garbage collects it.
  Permalink  
Comments
Jeneesh K. Velayudhan at 27-Jun-13 10:34am
   
Hi Ron Beyer,
 
Thanks for your response.
 
I have implemented the same GC.KeepAlive(cb);
 
But, still I am getting the same error on the next call.
 
Since it is an async call, it calls min 25 times in a sec.
 
Please suggest me any other solution for the same.
Ron Beyer at 27-Jun-13 17:46pm
   
Try declaring cb outside of the Initialize routine in the class code. Just declare it there, and in the Initialize routine you can initialize it. As long as you aren't calling the Initialize routine 25/sec then it should work.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thank you, Ron Beyer...
 
It worked...Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 28 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100