Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-16341] Amelioration of memory leak by at least interning som…
…e heavily redundant strings.

(cherry picked from commit 08efdf5)

Conflicts:
	changelog.html
	core/src/main/java/hudson/widgets/RenderOnDemandClosure.java
  • Loading branch information
jglick authored and vjuranek committed Jan 26, 2013
1 parent bd03abb commit 47d6811
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Reduced size of memory leak in render-on-demand functionality used e.g. in configuration pages.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16341">issue 16341</a>)
<li class=bug>
Fixed <tt>NoClassDefFoundError: Base64</tt> with the <tt>-jnlpCredentials</tt> option.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-9679">issue 9679</a>)
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/hudson/widgets/RenderOnDemandClosure.java
Expand Up @@ -25,15 +25,12 @@

import hudson.Util;
import hudson.model.Descriptor;
import hudson.model.DescriptorByNameOwner;
import hudson.util.IOException2;
import hudson.util.PackedMap;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.Script;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.bind.JavaScriptMethod;
Expand Down Expand Up @@ -61,6 +58,8 @@ public class RenderOnDemandClosure {
private final Map<String,Object> variables;
private final String currentDescriptorByNameUrl;

private final String[] adjuncts;

public RenderOnDemandClosure(JellyContext context, String attributesToCapture) {
List<Script> bodyStack = new ArrayList<Script>();
for (JellyContext c = context; c!=null; c=c.getParent()) {
Expand All @@ -72,12 +71,19 @@ public RenderOnDemandClosure(JellyContext context, String attributesToCapture) {

Map<String,Object> variables = new HashMap<String, Object>();
for (String v : Util.fixNull(attributesToCapture).split(","))
variables.put(v,context.getVariable(v));
variables.put(v.intern(),context.getVariable(v));

// capture the current base of context for descriptors
currentDescriptorByNameUrl = Descriptor.getCurrentDescriptorByNameUrl();

this.variables = PackedMap.of(variables);

Set<String> _adjuncts = AdjunctsInPage.get().getIncluded();
this.adjuncts = new String[_adjuncts.size()];
int i = 0;
for (String adjunct : _adjuncts) {
this.adjuncts[i++] = adjunct.intern();
}
}

/**
Expand Down

0 comments on commit 47d6811

Please sign in to comment.