Using one JaxBContext instead of making a new one each time is also nicer 
to your CPU, especially if you are running a lot of reports at the same 
time.  I made a custom serializer for this reason.  It should be easy to 
fix in the official library though.

On Monday, October 15, 2012 3:38:37 AM UTC-4, eli wrote:
>
> Hey,
> Not sure if this is the right forum for a bug report but here goes anyway.
> We've been using the ReportUtils class to download reports. In 
> v201206(adwords-api-8.7.0-loner.jar) you introduced a slightly different 
> mechanism for report downloading that uses jaxb to serialize the 
> ReportDefinition object. We noticed that our memory usage is steadily 
> increasing specifically in permgen. The reason was jaxb generated classes 
> related to ReportDefinition were loaded on each report download. After some 
> investigation we found that for each report download you create a 
> JAXBContext. The context should be created only once and reused as it 
> generates classes which never get unloaded.
> Code:
> in com.google.api.adwords.lib.utils.v201206.ReportUtils.toXml:
> public static String toXml(ReportDefinition reportDefinition) {
>     JaxBSerializer<ReportDefinition> serializer =
>         new JaxBSerializer<ReportDefinition>(ReportDefinition.class, new 
> QName("reportDefinition"));
>     return sanitize(serializer.serialize(reportDefinition));
>   }
>
> JaxBSerializer.serialize:
> public String serialize(T object) {
>     try {
>       *JAXBContext context = JAXBContext.newInstance(clazz);*
>       Marshaller marshaller = context.createMarshaller();
>       JAXBElement<T> element =
>           new JAXBElement<T>(qname, clazz, object);
>       StringWriter stringWriter = new StringWriter();
>       marshaller.marshal(element, stringWriter);
>       return stringWriter.toString();
>     } catch (JAXBException e) {
>       throw new SerializationException("Could not serialize object.", e);
>     }
>   }
>
> Thanks,
> Eli
>
>
>

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to