The use of PasswordDeriveBytes and RijndaelManaged produces .net memory leaks in the application. This occurs in .net 1.1 and 2.0, but 1.1 has more issues than 2.0.Doing a test with 5000 iterations over a function that does encryption, and after calling every Dispose, Clear or Close method available, some objects still remain in memory.Using psscor !dumpheap -stat on the dump after the processing, the results were: MT Count TotalSize Class Name0x79be5180 4,335 52,020 System.Security.Cryptography.RNGCryptoServiceProvider0x79c01c20 4,335 86,700 System.Security.Cryptography.__HashHandleProtector0x79bfde14 4,335 156,060 System.Security.Cryptography.MD5CryptoServiceProvider0x79c21764 4,335 225,420 System.Security.Cryptography.PasswordDeriveBytes0x79be5384 8,671 242,788 System.Security.Cryptography.CspParameters0x00150340 2,490 710,996 Free0x00a726b0 39,017 764,564 System.Byte[]0x79c209ac 13,002 832,128 System.Security.Cryptography.CryptoStreamAfter checking the code of PasswordDeriveBytes and RijndaelManager with netreflector, I detected 4 problems in PasswordDeriveBytes and 1 in RijndaelManager.The 4 problems in PasswordDeriveBytes are.Method ComputeBaseValue, CryptoStream object not disposed (1.1)Method ComputeBytes, two CryptoStream objects not disposed (1.1 and 2.0)Method CryptDeriveKey, SymmetricAlgorithm object not disposed (1.1)And the HashAlgorithm internal variable is never disposed when the PasswordDeriveBytes object is Disposed (1.1) or Finalized (2.0)After implementing my own PasswordDeriveByte class using .netreflector to get the code, and implementing the changes I'm suggesting, including a new dispose method, dumpheap -stat returned:0x00a7209c 13 10,776 System.Object[]0x00a72964 24 17,096 System.Int32[]0x79b925c8 325 24,312 System.String0x00150340 67 47,972 Free0x79be5180 4,335 52,020 System.Security.Cryptography.RNGCryptoServiceProviderAfter digging more code, I found that the RijndaelManaged never disposed the private variable _rng when it's being disposed and that has a reference to RNGCryptoServiceProvider. That variable holds the 4335 objects in memory..
Version