Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5112f86c
Unverified
Commit
5112f86c
authored
Oct 06, 2021
by
Dan Field
Committed by
GitHub
Oct 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear asset manager caches on memory pressure (#91353)
parent
22c1ca76
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
2 deletions
+44
-2
asset_bundle.dart
packages/flutter/lib/src/services/asset_bundle.dart
+9
-0
binding.dart
packages/flutter/lib/src/services/binding.dart
+3
-1
binding_test.dart
packages/flutter/test/services/binding_test.dart
+32
-1
No files found.
packages/flutter/lib/src/services/asset_bundle.dart
View file @
5112f86c
...
...
@@ -98,6 +98,9 @@ abstract class AssetBundle {
/// loaded, the cache will be reread from the asset bundle.
void
evict
(
String
key
)
{
}
/// If this is a caching asset bundle, clear all cached data.
void
clear
()
{
}
@override
String
toString
()
=>
'
${describeIdentity(this)}
()'
;
}
...
...
@@ -215,6 +218,12 @@ abstract class CachingAssetBundle extends AssetBundle {
_stringCache
.
remove
(
key
);
_structuredDataCache
.
remove
(
key
);
}
@override
void
clear
()
{
_stringCache
.
clear
();
_structuredDataCache
.
clear
();
}
}
/// An [AssetBundle] that loads resources using platform messages.
...
...
packages/flutter/lib/src/services/binding.dart
View file @
5112f86c
...
...
@@ -113,7 +113,9 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
/// [SystemChannels.system].
@protected
@mustCallSuper
void
handleMemoryPressure
()
{
}
void
handleMemoryPressure
()
{
rootBundle
.
clear
();
}
/// Handler called for messages received on the [SystemChannels.system]
/// message channel.
...
...
packages/flutter/test/services/binding_test.dart
View file @
5112f86c
...
...
@@ -51,8 +51,10 @@ class TestBinding extends BindingBase with SchedulerBinding, ServicesBinding {
}
void
main
(
)
{
final
TestBinding
binding
=
TestBinding
();
test
(
'Adds rootBundle LICENSES to LicenseRegistry'
,
()
async
{
TestBinding
()
.
defaultBinaryMessenger
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
?
message
)
async
{
binding
.
defaultBinaryMessenger
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
?
message
)
async
{
if
(
const
StringCodec
().
decodeMessage
(
message
)
==
'NOTICES.Z'
&&
!
kIsWeb
)
{
return
Uint8List
.
fromList
(
gzip
.
encode
(
utf8
.
encode
(
combinedLicenses
))).
buffer
.
asByteData
();
}
...
...
@@ -76,4 +78,33 @@ void main() {
equals
(<
String
>[
'L2Paragraph1'
,
'L2Paragraph2'
,
'L2Paragraph3'
]),
);
});
test
(
'didHaveMemoryPressure clears asset caches'
,
()
async
{
int
flutterAssetsCallCount
=
0
;
binding
.
defaultBinaryMessenger
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
?
message
)
async
{
flutterAssetsCallCount
+=
1
;
return
Uint8List
.
fromList
(
'test_asset_data'
.
codeUnits
).
buffer
.
asByteData
();
});
await
rootBundle
.
loadString
(
'test_asset'
);
expect
(
flutterAssetsCallCount
,
1
);
await
rootBundle
.
loadString
(
'test_asset2'
);
expect
(
flutterAssetsCallCount
,
2
);
await
rootBundle
.
loadString
(
'test_asset'
);
expect
(
flutterAssetsCallCount
,
2
);
await
rootBundle
.
loadString
(
'test_asset2'
);
expect
(
flutterAssetsCallCount
,
2
);
final
ByteData
message
=
const
JSONMessageCodec
().
encodeMessage
(<
String
,
dynamic
>{
'type'
:
'memoryPressure'
})!;
await
ServicesBinding
.
instance
!.
defaultBinaryMessenger
.
handlePlatformMessage
(
'flutter/system'
,
message
,
(
_
)
{
});
await
rootBundle
.
loadString
(
'test_asset'
);
expect
(
flutterAssetsCallCount
,
3
);
await
rootBundle
.
loadString
(
'test_asset2'
);
expect
(
flutterAssetsCallCount
,
4
);
await
rootBundle
.
loadString
(
'test_asset'
);
expect
(
flutterAssetsCallCount
,
4
);
await
rootBundle
.
loadString
(
'test_asset2'
);
expect
(
flutterAssetsCallCount
,
4
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment