Skip to content
  • nagachika's avatar
    b4f86234
    merge revision(s) b3d61280: [Backport #20150] · b4f86234
    nagachika authored
    	Fix memory leak in grapheme clusters
    
    	[Bug #20150]
    
    	String#grapheme_cluters and String#each_grapheme_cluster leaks memory
    	because if the string is not UTF-8, then the created regex will not
    	be freed.
    
    	For example:
    
    	    str = "hello world".encode(Encoding::UTF_32LE)
    
    	    10.times do
    	      1_000.times do
    	        str.grapheme_clusters
    	      end
    
    	      puts `ps -o rss= -p #{$$}`
    	    end
    
    	Before:
    
    	    26000
    	    42256
    	    59008
    	    75792
    	    92528
    	    109232
    	    125936
    	    142672
    	    159392
    	    176160
    
    	After:
    
    	    9264
    	    9504
    	    9808
    	    10000
    	    10128
    	    10224
    	    10352
    	    10544
    	    10704
    	    10896
    	---
    	 string.c                 | 98 +++++++++++++++++++++++++++++++-----------------
    	 test/ruby/test_string.rb | 11 ++++++
    	 2 files changed, 75 insertions(+), 34 deletions(-)
    b4f86234
    merge revision(s) b3d61280: [Backport #20150]
    nagachika authored
    	Fix memory leak in grapheme clusters
    
    	[Bug #20150]
    
    	String#grapheme_cluters and String#each_grapheme_cluster leaks memory
    	because if the string is not UTF-8, then the created regex will not
    	be freed.
    
    	For example:
    
    	    str = "hello world".encode(Encoding::UTF_32LE)
    
    	    10.times do
    	      1_000.times do
    	        str.grapheme_clusters
    	      end
    
    	      puts `ps -o rss= -p #{$$}`
    	    end
    
    	Before:
    
    	    26000
    	    42256
    	    59008
    	    75792
    	    92528
    	    109232
    	    125936
    	    142672
    	    159392
    	    176160
    
    	After:
    
    	    9264
    	    9504
    	    9808
    	    10000
    	    10128
    	    10224
    	    10352
    	    10544
    	    10704
    	    10896
    	---
    	 string.c                 | 98 +++++++++++++++++++++++++++++++-----------------
    	 test/ruby/test_string.rb | 11 ++++++
    	 2 files changed, 75 insertions(+), 34 deletions(-)
Loading