473,490 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Shared List from Compiler in a class with an event declaration

Hello
I've had strange memory problem with my application compiled in debug mode.
The problem is that in a visual basic class with an event declaration:
public class Class1

public event Pippo()

end class
in the class, the compiler add this code(I've found it with reflector):

Private Shared __ENCList As List(Of WeakReference)

Shared Sub New()
Class1.__ENCList = New List(Of WeakReference)
End Sub
Public Sub New()
Dim list As List(Of WeakReference) = Class1.__ENCList
SyncLock list
Class1.__ENCList.Add(New WeakReference(Me))
End SyncLock
End Sub

so after each creation of objects, the shared list add an weakreference
item, and never release it...If I need to create thousand and thousand object
of this class, the ram increase and after it goes also to more than 1Gb and
then in outofmemory exception.

Anyway if you compile this code in release mode, or in debug mode but with
"enable optimizations" this strange code disappear...so I resolved it without
big efforts...
But now I would know why the compiler add this weakreference in his shared
list and never remove it...
Thanks
Nov 21 '07 #1
0 1136

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

Similar topics

1
4393
by: AH | last post by:
I have two functions in my shared library which are declared as follows: void setName(const std::string& str); std::vector<std::string> getInfo(); Since the code is compiled and in shared...
10
3517
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base...
5
3004
by: CJ Taylor | last post by:
Hey all, This is probably a dumb question, but still feeling a little strange from Labor day festiviities. Anyways, I want a shared sub, at least something that is easy to call from any one...
7
9266
by: Iain Mcleod | last post by:
Hi This must be an often encountered problem. I want to declare an abstract class or an interface with nothing but several static constants so that I can use polymorphism when I call each of them...
4
15835
by: Brett | last post by:
I'm trying to use the F1 function inside of F2 function below. I keep getting the error posted below the code. If I remove the Shared declaration from F2, it works fine. What exactly does the...
3
10185
by: Boni | last post by:
Dear all, is it not possible to have shred events? Thanks, Boni error BC30600: 'WithEvents' variable does not raise any instance events that are accessible to 'Class A."
4
1963
by: Gregory Gadow | last post by:
I've cobbled together a PrinterClass that takes a text file and dumps it to a printer. The app using is has multiple threads, all of which need access to a shared instance. Can someone point me to...
4
2791
by: Cedric Rogers | last post by:
I wasn't sure if I could do this. I believe I am stretching the capability of what generics can do for me but here goes. I have a generic delegate defined as public delegate bool...
4
5528
by: l.s.rockfan | last post by:
Hello, how do i have to call an inherited, templated class constructor from the initializer list of the inheriting, non-templated class constructor? example code: template<typename T>...
0
7112
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
6974
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...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6852
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...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
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
3084
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
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.