473,508 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delegate Memory Leak

Hi all,

At this point of time i m totally confused... and really dont know what to
do...

Here is my query :

We have a class which we want to call in async manner and this is just a
test class.... but the problem is increasing memory.. so is there something
which i m doing wrong

below is the code:

Imports System.Runtime.Remoting.Messaging

Class Writer
Delegate Function AsyncWriteText(ByVal strText As String) As String

Private Function WriteSomething(ByVal strToWrite As String) As String
System.Threading.Thread.Sleep(2000)
Return strToWrite
End Function

Public Function BeginWriteSomething(ByVal strToWrite As String, ByVal
callback As System.AsyncCallback, ByVal asyncState As Object) As
System.IAsyncResult
Dim cd As AsyncWriteText = New AsyncWriteText(AddressOf
WriteSomething)
Dim result As IAsyncResult = cd.BeginInvoke(strToWrite, callback,
asyncState)
Return result
End Function

Public Function EndWriteSomething(ByVal Result As System.IAsyncResult)
As String
Dim Test As AsyncWriteText = CType(CType(Result,
AsyncResult).AsyncDelegate, AsyncWriteText)
Dim Obj As Object
Obj = Test.EndInvoke(Result)
Return CType(Obj, String)
End Function
End Class
OK above is the class which we want to call in asynchronously....

now this is our Form in which we call that method in a timer control and
invoke it every 1 sec.
Public Class Form1
Inherits System.Windows.Forms.Form
Dim ObjWriter As New Writer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.enabled = true
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
ObjWriter.BeginWriteSomething("chintan", AddressOf MyCallBack,
Nothing)
End Sub

'and now is the callback
Private Sub MyCallBack(ByVal ar As IAsyncResult)
'Execute this function after the delegate runs
Dim str As String
str = ObjWriter.EndWriteSomething(ar)
'Just log the string nothing else.
End Sub
Now.... what happens its works fine..... but the memory keeps on
increasing...and by some bytes.... eventually it will grow 1 mb after 15
minutes.

So i m confused.. where exactly the memory keeps on increasing.. Is that
something which i need to dispose before calling the Async. method.

Plz. help and correct me if i m writing the delegates in a wrong manner...
and if my code is wrong then plz can some give me exact answer for calling
delegates in asyn mode in a timer control.

Cheers
c
Nov 21 '05 #1
0 1062

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3394
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
4770
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
4
6056
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
8025
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
23
4509
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
8521
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
7
6914
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
3
5291
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
22
9303
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.