Title: Memory leak when using docx.Document() with io.Bytes · Issue #1364 · python-openxml/python-docx · GitHub
Open Graph Title: Memory leak when using docx.Document() with io.Bytes · Issue #1364 · python-openxml/python-docx
X Title: Memory leak when using docx.Document() with io.Bytes · Issue #1364 · python-openxml/python-docx
Description: Line # Mem usage Increment Occurrences Line Contents ============================================================= 37 65.7 MiB 65.7 MiB 1 @profile 38 def process_docx(docx_stream: IO[bytes]) -> list[str]: 39 """ 40 Process a DOCX documen...
Open Graph Description: Line # Mem usage Increment Occurrences Line Contents ============================================================= 37 65.7 MiB 65.7 MiB 1 @profile 38 def process_docx(docx_stream: IO[bytes]) -> lis...
X Description: Line # Mem usage Increment Occurrences Line Contents ============================================================= 37 65.7 MiB 65.7 MiB 1 @profile 38 def process_docx(docx_stream: IO[bytes]) -> ...
Opengraph URL: https://github.com/python-openxml/python-docx/issues/1364
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak when using docx.Document() with io.Bytes","articleBody":"```\r\nLine # Mem usage Increment Occurrences Line Contents\r\n=============================================================\r\n 37 65.7 MiB 65.7 MiB 1 @profile\r\n 38 def process_docx(docx_stream: IO[bytes]) -> list[str]:\r\n 39 \"\"\"\r\n 40 Process a DOCX document and extract text and images.\r\n 41\r\n 42 Args:\r\n 43 docx_stream (IO[bytes]): The input DOCX file stream.\r\n 44\r\n 45 Returns:\r\n 46 list[str]: A list of extracted text and images from the document.\r\n 47 \"\"\"\r\n 48 65.8 MiB 0.0 MiB 1 zip_file = zipfile.ZipFile(docx_stream)\r\n 49 71.3 MiB 5.6 MiB 1 document = docx.Document(docx_stream)\r\n 50 #docx_stream.close()\r\n 51\r\n 52 71.3 MiB 0.0 MiB 1 image_rels = {}\r\n 53 71.3 MiB 0.0 MiB 28 for rel in document.part.rels.values():\r\n 54 71.3 MiB 0.0 MiB 27 if isinstance(rel._target, docx.parts.image.ImagePart):\r\n 55 71.3 MiB 0.0 MiB 1 image_rels[rel.rId] = rel._target.partname\r\n 56\r\n 57 71.3 MiB 0.0 MiB 1 image_paragraphs = []\r\n 58 71.3 MiB 0.0 MiB 1 text_pages = []\r\n 59 71.3 MiB 0.0 MiB 1 current_page_text = ''\r\n 60 75.2 MiB 0.1 MiB 129 for element in document.iter_inner_content():\r\n 61 75.2 MiB 0.0 MiB 128 if isinstance(element, docx.text.paragraph.Paragraph):\r\n 62 75.2 MiB 0.0 MiB 125 current_page_text += element.text + '\\n'\r\n 63 75.2 MiB 0.1 MiB 125 if 'graphicData' in element._p.xml or 'Graphic' in element._p.xml:\r\n```\r\nThere is an increment in size there, but the memory is never released even when the function ends its execution, any solutions?\r\n\r\nPS: I tested and with file path it has the same issue","author":{"url":"https://github.com/Mathacc","@type":"Person","name":"Mathacc"},"datePublished":"2024-03-22T19:50:48Z","url":"https://github.com/python-openxml/python-docx/issues/1364"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0f37aec8-1ce2-b6ea-a90d-c696cd3bac62 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8C6:18718A:7A2D68:8D484C:6AFF6592 |
| html-safe-nonce | 2e40ed26b2837a74e3adaa9600a2ac23610d3dba1c3b1761c14c12116c0dd027 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEM2OjE4NzE4QTo3QTJENjg6OEQ0ODRDOjZBRkY2NTkyIiwidmlzaXRvcl9pZCI6IjUwNjEzMTI3MTYwNzgwMTU4OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 054a0fc74ebd60d84402b765fe43046e24836cddaedb5d999b5de8ffc141e1e2 |
| hovercard-subject-tag | issue:2203206977 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openxml/python-docx/1364/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ece9ccdc6d52971eefff930c1c3c1c7430a06bfdc14fc2067606798fd489f69/python-openxml/python-docx/issues/1364 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ece9ccdc6d52971eefff930c1c3c1c7430a06bfdc14fc2067606798fd489f69/python-openxml/python-docx/issues/1364 |
| og:image:alt | Line # Mem usage Increment Occurrences Line Contents ============================================================= 37 65.7 MiB 65.7 MiB 1 @profile 38 def process_docx(docx_stream: IO[bytes]) -> lis... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Mathacc |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b58589a1c4eda1e3c8904144a412b88ca4455f63ca2ad3629f2e9f3c3a1d12 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git |
| octolytics-dimension-user_id | 3403760 |
| octolytics-dimension-user_login | python-openxml |
| octolytics-dimension-repository_id | 13592924 |
| octolytics-dimension-repository_nwo | python-openxml/python-docx |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 13592924 |
| octolytics-dimension-repository_network_root_nwo | python-openxml/python-docx |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8968d6d6acc65d74e4df332d23932dd3fd0502a4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width