Garbage Collection On Callback From Unmanaged Dll
Nov 2, 2010
I am using a function from a dll in unmanaged code that requires a callback to my managed code in Visual Basic 2010. The callback is asynchronous and is called continuously over the life of the application. What's the best way to protect the callback function from the garbage collector? Right now it is being collected after several dozen calls from the dll.
View 11 Replies
ADVERTISEMENT
Jun 6, 2012
I am using vb.net 3.5 and application is interacting with VC++ dll.
code is:
Public Delegate Sub delProcess() //Globaly declare
im del As New delProcess(AddressOf Process) //Process is function which not returning
[code].....
View 1 Replies
Jul 23, 2010
I thought that when a variable went out of scope (like a variable declared within a method - when you exit that method the variable is out of scope) then it was eligible for garbage collection and when it was garage collected the Dispose method is called on it. Now I know that it does not get disposed immediately but I assumed it would be basically as soon as the process starts to take up quite a bit of memory.However, I found that my app's memory usage seems to constantly increase when I dont manually Dispose of a specific method local variable. Of course its good practice to call Dispose and ordinarily I would but I just didn't realise that this particular class actually implemented IDisposable. The class in question was the System.DirectoryServices.SearchResultCollection class, and I was looping through the items in it like so:
[Code]...
View 9 Replies
Jan 11, 2011
I'm creating a windows forms program and have recently noticed a large amount of memory slowly being eaten by the application. I went through my program and tried to tie up as many loose ends as I could in relation to object creation but noticed that the program would still keep memory for every form loaded until it eventually crashed.
I decided to make a simple test program which sole purpose is to pop-up a new form with a few controls, wait for 200 milliseconds, then close the form and repeat the process 30 times every time I hit a button. I found it caused the same behavior, even with the only new object creation being that of the form. So, I decided to manually invoke the garbage collector in a subroutine which handles the formclosed event. During tests I would get some memory back occasionally, but not enough to make a difference in the long run. So I start setting the form variable to nothing before I called GC.collect(). The program will initially eat a few 1000K of memory before leveling off and using only 20-40K for every 30 forms created.
Now what I'm wondering is, what is the point of an automated garbage collection system if it requires constant manual evocation and explicit dereferencing of all new objects to be effective? Have I completely lost grasp on the scope of VB.Net forms and it simply never marks forms as available memory to be cleared?I would have thought object memory references created within a form would be marked as usable when the form's close or dispose routine is called and no references to objects created within the form exist anywhere outside the closed form.
View 13 Replies
Sep 22, 2009
I am trying to create radiobuttons, and then create code for them after they are created. I have the code to create the radiobuttons. What I want to do is create a sub for the event of changing the check value for the radiobutton. Or to have the check value recognized by a button click. For example, you click the button and if the first radiobutton has the circle filled then a msgbox comes up and says hurray. My code so far is this:
View 6 Replies
Feb 21, 2012
I've been doing some reading on garbage collection in .NET and I was hoping for some clarification. So, as I understand it if I declare a public shared class variable, the GC will never get rid of it. Is this correct?Also, what then of private variables? Take the following example:
public class myClass
private shared myString As String
public sub ChangeString(newString As String)
[code].....
View 4 Replies
Oct 5, 2010
I have a callback function in a C+ dll:
<UnmanagedFunctionPointer(CallingConvention.Cdecl)> _
Public Delegate Sub DeviceDetectionEvent(ByVal YasdiEvent As YASDIDetectionSub, ByVal DeviceHandle As UInteger, ByVal param1 As UInteger)
[code].....
View 8 Replies
Jan 29, 2009
Is the memory from primitive data types (int, char,etc) immediately released once they leave scope, or added to garbage collection for later release?
consider:
For x as integer=0 to 1000
dim y as integer
Next
If this doesn't add 1000 integers to the garbage collector for clean up later,how does it treat string objects? would this create 1000 strings to clean up later?
For x as integer=0 to 1000
dim y as string=""
Next
How about structures that contain only int,string,etc... data types?
View 13 Replies
Oct 6, 2009
Datatable object within class function + garbage collection?
View 3 Replies
Feb 8, 2011
Here's the scenario, winforms application, monitoring via Task Manager Processes Tab.On initial launch spins up to ~61,000K (initial data grid and data loads)If I minimize the application, not touching or doing anything the Mem usage drops to 1,380K.When I restore the application is spins back up to only 5.8K
So my question is, does the minimize send some internal message to clean up resources since the application in question is not in focus?The first app I noticed this in happens to be VB.NET, but I've observed the same behavior in my main C# winform applications.
View 1 Replies
Jan 23, 2009
If I use a single variable of type Excel.Worksheet to reference Worksheet1, and then change it to Worksheet2, Worksheet3 and so on, is it adequate to simply do "Marshal.FinalReleaseComObject(worksheetVariable)" once at the end? Or would I be left with some references still in memory? In other words, do I need to do a "Marshal.FinalReleaseComObject" before each re-assignment?
View 3 Replies
Feb 3, 2010
I have a theory that the CLR garbage collection mechanism means that I can get away with circular references in my object hierarchy without creating deadlocks for teardown and garbage collection. Is this a safe assumption to make? (Target language VB.NET)
View 2 Replies
Jul 30, 2009
Dim x as whatever
Try
x = new whatever(1)
something is done with x
[code]....
What happens to x = whatever(1)Does garbage collection find the pointer to the first new and destroy it or what?
View 2 Replies
Mar 9, 2012
I've heard that the c# garbage collector can be 'more aggressive' than it's vb.net counterpart. Is this true? Are there any other differences in how garbage collection is run in vb.net vs. c#?
View 5 Replies
Jun 15, 2009
I'm trying to introduce delay to my code so that it would read in the noise or garbage data.
I'm receiving the data from RFID to pic thru RS232.Is there any simple delay that i can use? I seriously don't understand threading.
View 1 Replies
Dec 4, 2010
I have a function like the following: Public Function testFunction(ByVal input_string As String) As String
[Code]...
or just let the garbage collector do the job for us? Both the above functions work, but I want only know the best practice for performance...
View 6 Replies
Mar 2, 2010
I'm using following code to receive content of a ListBox
View 3 Replies
Sep 28, 2009
If I want to narrow scope of a variable in C#, I can introduce additional braces - i.e.:
class Program
{
static void Main(string[] args)[code].....
In the ide, I can no longer reference y outside of the scope introduced by the new braces. I would have thought that this would mean that the variable y would be available for garbage collection.(it is interesting to note that when viewing the compiled code using reflector it appears that there is no difference with or without the additional braces)Is there any way similar to this to narrow scope when using VB.net? Does this have any impact on when variables defined in the inner scope may be garbage collected?
View 4 Replies
Oct 25, 2010
with VB.NET + MySQL i am having a connection object which is public public MYcnn as MySql.Data.MySqlClient.MySqlConnection when my main form opens MYcnn will open & will be available for all the procedures & functions. i never close this connection until the last form of the application closes (yes of course i compromise of some security + performance issues)
my problems is(1)when & how the garbage collector works to collect my connection object if my connection object remains open for > then certain time(2) how to offer or fix the time of my connection object availableness to garbage collector (3) i would like to write an event for the connection object closed event(i am explicitly declaring the connection object)
View 5 Replies
Nov 26, 2010
I have an Excel file that downloads automatically, but for some reason the binary XLS file contains some garbage HTML text at the end of it.
When opening the file in the Excel application, it shows a warning but proceeding will automatically remove the garbage HTML text.
However, I need to open the file programmatically. When doing so via
Dim wb As Workbook = Excel.Workbooks.Open(ExcelFileName)
It throws:
Exception from HRESULT: 0x800A03EC
a) Get Excel to perform a similar action as if I manually opened it and remove the garbage HTML automatically. NOTE: Tried setting the XlCorruptLoad.xlRepairFile parameter and it didn't work.
OR
b) Remove the garbage text from the XLS binary file (FileStream?) and resave it before attempting to open the file with the code mentioned above.
The garbage html always comes at the very end of the file and starts with
View 1 Replies
Jun 19, 2012
I'm trying to use a .DLL which Callbacks a Function of my project, but I can't get it to work.
Declaration from .h file of .DLL
void DLL_EXPORT SetEntity_CallBack(bool Active, _
void (*Entity_Callback)(int Site, int Application, int ID, _
[Code].....
View 11 Replies
Jan 8, 2010
i need to pass commands through a C++ dll to vb.net and the other way around. is there some code that needs to be in the C++ dll to make it work? im not good at C++ at all,
View 5 Replies
May 1, 2012
I have a problem with an application, in this case I have a windows services. its function is generate reports depending of demand of our users.In some cases the memory usage of my windows services is to 2 gb of RAM. I disposed all objects that my application use . but the memory usage doesn't low.I tried to reduce the memory usage forcing to garbage collector to Collect with the method "GC.Collect"but it's not recommend because uses many time of CPU.Surfing on the internet I found a method named "SetProcessWorkingSetSize" that free memory usage correctly. http:[url]....but some cases my windows services named sapdkadm_procesoestandarejecucion.exe has some error message in event viewer is the next:
Faulting application sapdkadm_procesoestandarejecucion.exe, version 1.0.0.0, stamp 4f908fef, faulting module kernel32.dll, version 5.2.3790.4480, stamp 49c51cdd, debug? 0, fault address 0x0000000000027ded.
The real problem is that when this happens my windows services restart
View 3 Replies
Jan 15, 2010
Is it good practice to store sub-collections of item X inside a parent collection of item X for caching 'filter-queries' which are performed on the parent collection? (They won't be used together (as in color AND type).) Or is it also ok to just Loop over the collection and return the correct entities in a temporary collection?
[Code]...
View 1 Replies
Oct 9, 2010
im trying to make a simple wrapper for lua. The only problem so far is that lua only accepts a method in a specific format.Delegate Function LuaC Function(ByVal lua_state As IntPtr) As Integer..That is how lua wants the method to look like. So it only accepts a function that looks like this: [code]
View 2 Replies
Aug 17, 2009
I have this code obtaining data from a sensor that is sending a string that contains 4 numbers separated by a tab and terminated by an end of line/ I am trying to use an asynchronous callback to get the data over TCP. That problem is that the callback function is not grabbing the complete string. Sometimes it will, other times it gets half in one retrieve and half in another. I need the callback to hold off until it gets a newline character.
Code:
Public Sub readVaisala()
Dim ip As String = "192.168.1.30"
Dim portNumber As Integer = 23
Dim time As Int32 = Now.Second * 1000 + Now.Millisecond
[code].....
View 2 Replies
Mar 3, 2011
I have a C++ dll that contains a callback. The callback has one parameter that is passed in and one parameter that is passed out. The parameter that is passed from C++ is a variant. So, we are going from a variant in C++ to an object in VB.NET. The function works. However, It seems that there is a memory leak on the VB.Net side. This must be a Marshaling issue. I have tried to use the MarshalAs Functions, but to no avail.
VB.NET
Declare
Function EnableWriteNotification
Lib
[code]....
View 2 Replies
Jan 4, 2011
there is error when i use callback function A callback was made on a garbage collected delegate of type 'skynet1!skynet1.Form1+myCallBack::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.
View 6 Replies
Aug 8, 2011
I am working on a Twitter application and with the authentication process, Twitter returns Two Tokens with a Callback URL, For example: [URL]. How do I extract each token and put them into separate strings?
View 5 Replies
May 12, 2011
I am writing classes in VB.Net (both managed). The main class "A" creates an instance of "B". Class "B" must call a method of Class "A". I need to know two things (syntax, etc...):
1. How does class "A" tell class "B" what method to call?
2. How does class "B" call the method?
The method must pass back an array of Shorts (in this particular example), either as a return value, or as a ByRef argument.I don't want to use an event if I don't have to. The execution is timing critical. (I assume event handling involves a lot of overhead by the operating system, but I may be wrong.)
View 1 Replies