View Issue Details

IDProjectCategoryView StatusLast Update
0030661LazarusLCLpublic2017-06-05 00:08
ReporterjakyroAssigned ToMichl 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformOSWindowsOS Version10
Product Version1.6Product Build51630 
Target Version1.8Fixed in Version1.9 (SVN) 
Summary0030661: TTreeView memory leak (WARNING: TResourceCacheItem.IncreaseRefCount 1000 TPenHandleCache)
DescriptionTreeView memory leak.

Create Win32/64 LCL application, add TreeView on MainForm, run and start resize MainForm until the message in console/log:

WARNING: TResourceCacheItem.IncreaseRefCount 1000 TPenHandleCache
WARNING: TResourceCacheItem.IncreaseRefCount 10000 TPenHandleCache

I tested it on Windows 10.0.10586 and 10.0.14393.
Steps To ReproduceWindows 10.0.10586/10.0.14393
lazarus-1.6.0-fpc-3.0.0-win32/win64 2016-02-15

1. Create LCL graphical application "Menu/File/New.../Project/Application".
Create MainForm if not created.

2. Create TreeView on MainForm and add TreeView items 1 or more.

3. Uncheck "Project Options.../Config and Target/Win32 gui application (-WG)" to see console messages OR run application with argument "--debug-log=log.txt".

4. Run application. Start resize MainForm (for repaint TreeView) from current size to zero and back, until the message (or close application to save log.txt if application running with --debug-log):

WARNING: TResourceCacheItem.IncreaseRefCount 1000 TPenHandleCache
WARNING: TResourceCacheItem.IncreaseRefCount 10000 TPenHandleCache
Additional InformationWARNING: TResourceCacheItem.IncreaseRefCount 1000 TPenHandleCache
WARNING: TResourceCacheItem.IncreaseRefCount 10000 TPenHandleCache
TagsIncreaseRefCount, lcl, TPenHandleCache, TResourceCacheItem, ttreeview, warnings
Fixed in Revisionr55118
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

jakyro

2016-09-28 13:54

reporter  

treeview-cache.png (39,886 bytes)
treeview-cache.png (39,886 bytes)

Mattias Gaertner

2016-09-28 14:21

manager   ~0094851

How often do you need to resize?

I can't reproduce the bug under Linux/Gtk2. Maybe Win32 only issue.

Bart Broersma

2016-09-28 15:24

developer   ~0094852

Last edited: 2016-09-28 15:48

View 2 revisions

Lazarus 1.7 r52861 FPC 3.0.0 i386-win32-win32/win64

I automated the resize:
Counter = 165
WARNING: TResourceCacheItem.IncreaseRefCount 1000 TPenHandleCache
Counter = 1665
WARNING: TResourceCacheItem.IncreaseRefCount 10000 TPenHandleCache

Note: the TreevIew must have Items, otherwise this issue does not happen.

Bart Broersma

2016-09-28 15:47

developer   ~0094853

While redrawing, all calls to TPen.FreeReference say: FReference.Allocated=FALSE
and also in all calls to TPen.ReferenceNeeded it says FReference.Allocated=FALSE

So, pens are added to the cache, but never seem to get deleted from it.

jakyro

2016-09-30 04:54

reporter   ~0094878

How to fix it?
I can not continue to create my project with this bug.

Mattias Gaertner

2016-09-30 08:45

manager   ~0094880

I can't reproduce the bug under Windows either.

Please attach an example unit to reproduce the problem.

Bart Broersma

2016-09-30 18:25

developer  

tvpencache.zip (65,635 bytes)

Bart Broersma

2016-09-30 18:28

developer   ~0094882

Last edited: 2016-09-30 18:28

View 3 revisions

Sample project attached (tvpencache.zip).
Unzip, build and run from commandline like this:

C:\Users\Bart\LazarusProjecten\bugs\TreeViewPenCache>tvpencache | grep WARNING --before-context=1

Output on my system
(Lazarus 1.7 r52861 FPC 3.0.0 i386-win32-win32 on Win7-64):

Counter = 165
WARNING: TResourceCacheItem.IncreaseRefCount 1000 TPenHandleCache
--
Counter = 1665
WARNING: TResourceCacheItem.IncreaseRefCount 10000 TPenHandleCache

Zeljan Rikalo

2016-09-30 18:48

developer   ~0094883

I can confirm this issue under win32. Does not happen with qt under win32, also does not happen under linux gtk2/qt.

jakyro

2016-09-30 19:21

reporter  

example_treeview_warning.zip (65,636 bytes)

Bart Broersma

2016-09-30 21:52

developer   ~0094884

> I can not continue to create my project with this bug.

I ran my sample program for > 500000 iterations.
There were no errors, crashes or Windows complaining.
Also heaptrace reported no memory leaks.

So, whilst this is a bug, it should not prevet you from developing your program.

Michl

2017-05-29 08:31

developer   ~0100733

Fixed in trunk. Please test and close if OK.

Btw. there was no memory leak. A new pen wasn't created, because the parameter list was wrong, so Handle 0 was given back. For this Handle 0, the reference count was increased.

Issue History

Date Modified Username Field Change
2016-09-28 13:54 jakyro New Issue
2016-09-28 13:54 jakyro File Added: treeview-cache.png
2016-09-28 14:01 jakyro Tag Attached: lcl
2016-09-28 14:01 jakyro Tag Attached: ttreeview
2016-09-28 14:01 jakyro Tag Attached: warnings
2016-09-28 14:01 jakyro Tag Attached: IncreaseRefCount
2016-09-28 14:01 jakyro Tag Attached: TPenHandleCache
2016-09-28 14:01 jakyro Tag Attached: TResourceCacheItem
2016-09-28 14:21 Mattias Gaertner Note Added: 0094851
2016-09-28 15:24 Bart Broersma LazTarget => -
2016-09-28 15:24 Bart Broersma Note Added: 0094852
2016-09-28 15:24 Bart Broersma Status new => confirmed
2016-09-28 15:47 Bart Broersma Note Added: 0094853
2016-09-28 15:48 Bart Broersma Note Edited: 0094852 View Revisions
2016-09-30 04:54 jakyro Note Added: 0094878
2016-09-30 08:45 Mattias Gaertner Note Added: 0094880
2016-09-30 18:25 Bart Broersma File Added: tvpencache.zip
2016-09-30 18:28 Bart Broersma Note Added: 0094882
2016-09-30 18:28 Bart Broersma Note Edited: 0094882 View Revisions
2016-09-30 18:28 Bart Broersma Note Edited: 0094882 View Revisions
2016-09-30 18:48 Zeljan Rikalo Note Added: 0094883
2016-09-30 19:21 jakyro File Added: example_treeview_warning.zip
2016-09-30 21:52 Bart Broersma Note Added: 0094884
2017-05-29 08:31 Michl Fixed in Revision => r55118
2017-05-29 08:31 Michl Note Added: 0100733
2017-05-29 08:31 Michl Status confirmed => resolved
2017-05-29 08:31 Michl Fixed in Version => 1.9 (SVN)
2017-05-29 08:31 Michl Resolution open => fixed
2017-05-29 08:31 Michl Assigned To => Michl
2017-05-29 08:31 Michl Target Version => 1.8